+ 1

a program which will allow people to drink beer based on their age and gender. .but i am not able to associate the gender part

how t assign that character value of male (m) and female (f) ..so that it would be able to decide based on age and gender? ????

2nd Aug 2017, 4:45 AM
Himanshu Bag
Himanshu Bag - avatar
4 Réponses
+ 5
a = int(input("age?")) g = input("gender? (m/f)") if a >= 19 and g == "f": print("OK you can have a beer.") if a < 19: print("Sorry, you're too young to drink beer.") if g == "m": print("Sorry, males are not allowed to drink beer ;)")
2nd Aug 2017, 5:15 AM
David Ashton
David Ashton - avatar
+ 5
The first 'If' is the simultaneous use of 2 conditionals. The second and third aren't really necessary for the algorithm - they just explain to the users why they can't have a beer.
3rd Aug 2017, 1:21 AM
David Ashton
David Ashton - avatar
0
You can just define what is the minimum age for (m) and (f) based on that you can decide whether he or she is allowed to drink beer.
2nd Aug 2017, 5:10 AM
Sudheer
Sudheer - avatar
0
if you want to use both age and gender simultaneously by conditional operation. .then???
2nd Aug 2017, 6:16 AM
Himanshu Bag
Himanshu Bag - avatar