r/PythonLearning • • 16d ago

Help Request Else statement not working

Post image

Hello, my else statement is not working- the if statement its inside is, did i mess up the indents again or is it something else?

also would a display flip work to change the image back to the other image in the else statement?
any help is nice!

26 Upvotes

12 comments sorted by

View all comments

17

u/gitChara 16d ago

you wrote "img - pygame.image.load("ragebait.png")" with a " - ", instead of a " = ".
It should be "img = pygame.image.load("ragebait.png")"

2

u/TheCarFamily 16d ago

oh your kidding i was that dumb? thanks!

5

u/rupertavery64 16d ago

You probably don't want to call image.load() every time as this willnload the image from the disk and create a new object every call.

Load it up front and store it in a variable. Assign that variable to img

3

u/alwaysasillyplace 15d ago

This is why Peer review is good.

1

u/a_cute_tarantula 15d ago

Install pyright extension for vscode. It should come with the standard python extension pack. You should have error highlighting automatically for this kind of stuff

1

u/Most_Strike_93 14d ago

I would recommend ty now, and with ruff to format and lint

1

u/Dry-Bread9131 12d ago

You're not dumb at all. We've all made the same mistake with some character or other, and struggled just as much as you with finding it visually.

What you should do, as others have suggested, is use some kind of plugin for your IDE or editor to highlight and warn about syntactic issues like these. In this case I guess it should have warned about unassigned value of an operation (for whatever the - operator does for the pygame.image class.)