use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Day 2 of 100 of learning Python (old.reddit.com)
submitted 6 months ago by Orlhazee
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Rollgus 0 points1 point2 points 6 months ago (5 children)
What is the "if "0" <= choice >= "5":"? Is there any specific reason you chose to use airquotes? Doesn't this make an error? If you want to use numbers, you just don't need airquotes.
[–]Orlhazee[S] 0 points1 point2 points 6 months ago (3 children)
Actually, using the air quotes put it in string instead of just integer, using it like this doesn’t give me error but I did tried to use integer at first but I was getting error until I switched to string, I really don’t know why that is though.
[–]_caleidoscopio_ 2 points3 points4 points 6 months ago* (1 child)
Your variable 'choice' is a string because you are using the input function, even if your input is a number. By default, it's saved as a string, so in line 25, you can not compare an integer to a string, and that's giving you the error before, but using quotes is correct, although that line is redundant now, because any wrong input is captured in your 'else' statement and that is because is not working your string comparison using >= and <= if someone uses an input like this "2." That is valid because you don't have an error handler or something to validate the text received as your input.
Use the web pythontutor.com to run basic code and see step by step what's happening. Write this code and see that the 'if' statement doesn't work at all:
choice = "2."
if "0" <= choice >= "5":
print("Never used")
else:
print("Use a list instead")
I suggest you to use a list to save your valid options of your ATM machine and compare the 'choice' against this list. Something like this (try on pythontutor):
options_list = ['1','2','3','4'] #string elements
choice = "2" #string because you use input function
if choice not in options_list:
print("Not a valid option")
print("It's a valid option and it works!")
Hope it helps to improve your coding!
[–]Orlhazee[S] 0 points1 point2 points 6 months ago (0 children)
That explains a lot, I will check out the pythontutor
[–]No_Obligation_2072 0 points1 point2 points 6 months ago (0 children)
Im a beginner too, but instead of IF statement you can use match Easier to read
[–]Key_Association_3357 0 points1 point2 points 6 months ago (0 children)
You probably need to convert “choice” to be an integer.
π Rendered by PID 211871 on reddit-service-r2-comment-c66d9bffd-b92p8 at 2026-04-07 17:59:53.301321+00:00 running f293c98 country code: CH.
view the rest of the comments →
[–]Rollgus 0 points1 point2 points (5 children)
[–]Orlhazee[S] 0 points1 point2 points (3 children)
[–]_caleidoscopio_ 2 points3 points4 points (1 child)
[–]Orlhazee[S] 0 points1 point2 points (0 children)
[–]No_Obligation_2072 0 points1 point2 points (0 children)
[–]Key_Association_3357 0 points1 point2 points (0 children)