0

I wanted a code that prints hi if the user does not type in 1,2,3, else it asks the user to type in an answer again. However, I don't understand what is wrong with my code. However, whatever I type in, the loop will keep asking me to input the number again.

choice=input('Your choice:')
while(choice != 1 or choice !=2 or choice != 3):
    choice=input('Please input only 1, 2 or 3:')
    print(choice)
else:
    print('hi')

Thank you!

Rapiddagger
  • 103
  • 6
  • 2
    choice is a string, not an integer – Sayse Feb 06 '18 at 08:43
  • 3
    Also your logic is wrong, what if it *was* `1`? – jonrsharpe Feb 06 '18 at 08:44
  • 1
    @jonrsharpe What do you mean? – Ma0 Feb 06 '18 at 08:45
  • 1
    @Ev.Kounis - It looks like the description is wrong, it states it wants to print hi if the user *doesn't* type in one of those numbers – Sayse Feb 06 '18 at 08:46
  • @Ev.Kounis what if `choice = 1`, which branch gets executed? – jonrsharpe Feb 06 '18 at 08:46
  • @jonrsharpe Oh.. The same holds for all of them actually (`1`, `2`, `3`). `while choice not in (1, 2, 3):` would be the way to go. – Ma0 Feb 06 '18 at 08:49
  • Hmm, since this question is not tagged python3, are you sure it is a duplicate ? and not just what @jonrsharpe says ? – Faibbus Feb 06 '18 at 08:50
  • 1
    @Faibbus as the OP didn't provide which interpreter or a [mcve] as to what they mean by *"wrong"*, it seems pointless to reopen without a further [edit] from them, which is what the banner suggests they do anyway. – jonrsharpe Feb 06 '18 at 08:51

0 Answers0