-3
vari1='a'
# choices are  all ready printed above.
while vari1 != 'o' and vari1 != 'O' and vari1 != 'p' and vari1 != 'P':
      vari1=input("please enter your choice.")
      if vari1 != 'o' and vari1 != 'O' and vari1 != 'p' and vari1 != 'P':
            print("please enter a appropriate choice") 

I tried this code but its not working. I wanna know how many logical operator I can use in one statement. I think there is some problem with my condition.

1 Answers1

1

better to use in this way:

while True:
    vari1=input("please enter your choice.")
    if vari1.lower() not in ['o','p']:
        print("please enter a appropriate choice") 
    else: 
        # do your stuff 
        break

str.lower convert string to lowercase.

demo:

>>> 1 in [1,2,3,4,5]
True
>>> 1 not in [1,2,3,4,5]
False
>>> 1 in [2,3,4,5]
False
>>> 1 not in [2,3,4,5]
True
Hackaholic
  • 19,069
  • 5
  • 54
  • 72