0

Beginner, Trouble with OR operators

Code: print('How old are you?') age=int(input()) if age<21: print('You\'re underaged? get out of my bar!') if age>=21: print('Alright! ' + 'What would you like to drink?') drink=input() if drink =='beer': print('*pours beer*') print('There you are!') elif drink =='whiskey'or 'vodka' or 'alcohol' or 'rum': print('*pours shot of '+ drink + '*') print('There you are!') else: print('We don\'t serve that here') Issue: My problem is that you can input anything as a drink and it will print "print('*pours shot of '+ drink + '*')". so you can input 'cheese' and my virtual bartender will pour you a shot of cheese. Can someone explain why this is not working?

29th Feb 2020, 3:33 PM
aaron bastian
aaron bastian - avatar
3 odpowiedzi
+ 7
I think the problem is in the elif drink == 'whiskey' or 'vodka' or 'alcohol' or 'rum' change it to elif drink == 'whiskey' or drink == 'vodka' or drink == 'alcohol' or drink == 'rum': you can also do elif drink in ['whiskey', 'vodka', 'alcohol', 'rum']: print('*pours shot of' + drink + '*') And try again... If that doesn't fix it then I will try something else
29th Feb 2020, 3:47 PM
Utkarsh Sharma
Utkarsh Sharma - avatar
+ 3
Your elif should be like this elif drink == "whiskey" or drink == "vodka" or....
29th Feb 2020, 3:48 PM
Mihai Apostol
Mihai Apostol - avatar
+ 3
@Utkarsh Sharma. That worked! That makes sense, this was the first time I used OR operators. I'm trying to update this little exercise code as I learn the new things to make it more concise, so I'll probably change it to the second thing you suggested once I get there.
29th Feb 2020, 4:04 PM
aaron bastian
aaron bastian - avatar