import random
from PIL import Image
import os
floaders = int(input("Введите количество папок: "))
for a in range(floaders):
os.mkdir(str(a))
lis = []
while len(lis) < 10:
num = random.randint(0, 38)
if num not in lis:
lis.append(num)
for i in lis:
try:
img = Image.open(str(i) + '.jpg')
crop_img = img.crop((random.randint(50, 90),
random.randint(50, 90),
random.randint(img.width - 60, img.width - 40),
random.randint(img.height - 60, img.height - 40)))
crop_img.save(os.path.join(str(a), str(i) + '.jpg'))
except FileNotFoundError:
print(f"File {i}.jpg not found")
print(a, lis)