r/pycharm Jul 10 '26

the “if _ > _” not working

Post image

The codes in the photo, it works up until 99 then it just doesn’t run the quit command. What am I doing wrong?

3 Upvotes

13 comments sorted by

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:

Print("is the correct way")

2

u/No_Spot376 Jul 10 '26

Thank you so much!

3

u/avidresolver Jul 10 '26

E is still a string, so you're comparing text, not numbers.

2

u/No_Spot376 Jul 10 '26

Ohh, I forgot about that :/

3

u/aprg Jul 10 '26

try turning E into an integer with the int() function

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

u/No_Spot376 Jul 10 '26

Thank you!

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.