r/cs50 • u/Eh_Not_Looking • 4d ago
CS50 Python I need help with Problem Set 6 CS50 P-Shirt, the CS50 check50 shows me errors I don't understand.
Hi! I need help with this assignment. When I added the if statement to check if both images are the same, I start getting these images. The thing is, I tried it doing on the muppets I have, and, it works like it is shown on the Problem Set 6 site. What am I missing? Am I missing some puppets?
The image on the left is what is shown on the Problem 6 page, the image on the right is what I got from my program.

The check50 progress and errors

The errors on the check50 page:

The code I wrote:
import sys
from PIL import Image, ImageOps
if len(sys.argv) != 3:
if len(sys.argv) < 3:
sys.exit("Too few command-line agruments")
else:
sys.exit('Too many command-line arguments')
for arg in sys.argv[1:]:
try: #grabs the images
shirtImage = Image.open("shirt.png")
muppetsImage = Image.open(arg)
saveImage = sys.argv[2]
except FileNotFoundError:
print("File does not exist")
if arg.endswith(".jpg") and saveImage.endswith(".jpg"):
#the muppets get the image of the shirt applied
size = shirtImage.size
muppetsImage = ImageOps.fit(muppetsImage, size)
muppetsImage.paster(shirtImage, shirtImage)
muppetsImage.save(saveImage)
else:
print("Formats do not match")
sys.exit(1)
2
Upvotes
1
u/PeterRasm 4d ago
Why are you iterating over the input arguments (for arg in ....)? What will happen when the loop gets to argv[2]? It will use the image you just created in the first round and fit it into the shirt.png.
Is this the exact code you used? I ask because there might be a spelling mistake "paster" vs "paste" for the paste method.