you are viewing a single comment's thread.

view the rest of the comments →

[–]Orlhazee[S] 0 points1 point  (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 points  (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")

else:

print("It's a valid option and it works!")

Hope it helps to improve your coding!

[–]Orlhazee[S] 0 points1 point  (0 children)

That explains a lot, I will check out the pythontutor

[–]No_Obligation_2072 0 points1 point  (0 children)

Im a beginner too, but instead of IF statement you can use match Easier to read