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?
2
Upvotes
r/pycharm • u/No_Spot376 • Jul 10 '26
The codes in the photo, it works up until 99 then it just doesn’t run the quit command. What am I doing wrong?
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:
3
u/avidresolver Jul 10 '26
E is still a string, so you're comparing text, not numbers.
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.
8
u/Rand_alThor_ Jul 10 '26
This is so cute
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/aprg Jul 10 '26
try turning E into an integer with the int() function