0

i'm trying to make sure the user enters either 1 or 2 when asked for input, and if the input is not a digit, or it is a digit but not 1 or 2, then it will keep asking them for the input until they enter one that meets my requirements. I currently have this but can't seem to get it to work. What am I doing wrong and any suggestions on fixing it? Thanks

option1 = input("Path 1 or Path 2(enter 1 or 2): ")
while (not option1.isdigit() and int(option1) != 1 or int(option1) != 2):
    print('Sorry, only the integer 1 or 2 is allowed. Try again. ')
    option1 = input("Path 1 or Path 2(enter 1 or 2): ")
M.G
  • 440
  • 1
  • 3
  • 10
  • `option1` and `userOption` are not the same variable. Why would you expect that code to work? – John Coleman May 25 '16 at 10:35
  • You fixed that bug -- why not drop `isdigit` completely and use a simpler test involving just the *strings* `"1"` and `"2"`? In this context `isdigit` is superfluous and seems to be confusing you. – John Coleman May 25 '16 at 10:40
  • 1
    `x!=a or x!=b` will always succeed. I suggest brushing up on your discrete logic after checking out the linked duplicate. – TigerhawkT3 May 25 '16 at 10:40

0 Answers0