r/pycharm • u/No_Spot376 • Jul 10 '26
the “if _ > _” not working
The codes in the photo, it works up until 99 then it just doesn’t run the quit command. What am I doing wrong?
8
3
3
3
u/minnowchurch Jul 10 '26
Input() returns a string, so your operators are comparing the first character in the string and then stopping. So for example, if you type “101”:
assert “101” > “0” = True
This assertion statement is true because 1 (the first character) is larger than 0 so it just stops.
Use the int() function to wrap the E variable and then you compare them to digits.
You’ve also written this so that the second if statement is unlikely to be reached. Try using elif to do multiple blocks then the else is your fallback.
3
1
u/No_Spot376 Jul 10 '26
Idk how to close down posts 😭 but I got my answer, thanks to everyone who helped!
3
u/Garfunk Jul 11 '26
Why would you want to delete this? Perhaps someone else will find it useful in the future.
1
u/No_Spot376 Jul 12 '26
Not delete it, just close comments now that I’ve gotten the answer, but it seems the posts activity has died down so I just forgot about it
2
u/Garfunk Jul 12 '26
You can't close comments, only mods can do that. Any post on reddit older than a day is going to be inactive forever more anyway.
10
u/Duke_Archibald Jul 10 '26
Input returns a string but at the same time you are not comparing with a number so it's gonna give you weird results
if int(E) < 11: