lundi 9 septembre 2019

Python: Multiple if statements not working with or

I want to compare two ints. One of the ints is an input. The other one is a number. When compared single it is working but when i chain them with or, nothing is working. I know that multiple 'if' should work but i want to spare some line of code. It is working in other languages.

I tried multiple codes. I used 'not' i used ',' i used to write the whole thing after the 'or'. Nothing is working.

test1 = input("Put in a number: ")

if(int(test1) != 1 or 2 or 3):
   print("Please put in 1 or 2 or 3")
   exit()

I expect that when the input is not 1,2 or 3 it would run the if otherwise go on with the code.

Aucun commentaire:

Enregistrer un commentaire