hypersonicelf
hypersonicelf

Reputation: 1

Using if statements to check against 2 possibilities

I wish to have hobAsk to be either y or n. If I type in y it accepts up it ignores the second value, n. Is it even possible to check against two variables in an if statement and if so how is it achieved?

 hobAsk = "f"
 total = 0

 while hobAsk != ("y" or "n"):   
     hobAsk = input("Will you go to Hobbiton($10)? (y/n)")
 hobAsk = hobAsk.lower()
 if hobAsk != ("y" or "n"): 
    print ("Invalid input")
 elif hobAsk == "y":
    total = total + 10
 print (total)        

Upvotes: 0

Views: 35

Answers (2)

Scott Hunter
Scott Hunter

Reputation: 49803

One correct translation of

is hobAsk neither "y" nor "n"

Would be

if hobAsk not in ("y","n"):

Upvotes: 2

Amrinder Singh
Amrinder Singh

Reputation: 5482

try something like this:

if not (var1 == 80 or var1 == 443 or (1024 <= var1 <= 65535)):

Upvotes: 0

Related Questions