+ 1
Why Is my code not working?
I'm trying to make a drinking calculator. I'm struggling at the point where if someone is under the age of 18 and they choose an alcoholic drink; it will say error as the choice==drinks in list drinks will come with error as it is not defined. However the IF statement above comes out as true and seems correct. https://code.sololearn.com/cA2031A1A19a/#py
1 Réponse
+ 3
In the following piece of code ,
"if age <= 17:
for non_drink in nonDrinks:
print(non_drink)
elif age >= 18:
for drink in drinks:
print(drink)"
If age is 18 and above it creates a drink variable with last value in drinks assigned to it , i.e. drink="Wine" but if if age is 17 or less it creates a non_drink variable with last value of nonDrinks assigned to it, i.e. non_drink="O_Juice".
You can check it yourself by printing global variables dictionary after line 23 as => print(globals())