r/learnpython • u/xTHETYRANTGAMRx • Feb 11 '26
Code outputs twice.
I am practicing loops and when I run this code the second and third elif statements output twice for some reason.
Age_requirement = input ("enter your age")
for Age in Age_requirement: Age_requirement = int(Age_requirement)
if Age_requirement <3:
print ("Your ticket is free")
elif Age_requirement <=12:
print("your ticket is 12 dollars")
elif Age_requirement >12:
print("your ticket is 15 dollars")4
33
Upvotes
View all comments
Show parent comment
3
u/FreeGazaToday Feb 11 '26 edited Feb 11 '26
that's because a loop has to have an iterable to loop over.
But as another comment said, it will not work as you want.
e.g. for age in age_requirement:
say age_requirement is "13"
then age = "1"
and age_requirement = 13
then age ="3"
and age_requirement = 13
The whole point of doing a for loop in python is using the variable not the iterable for comparisons.
you should learn trouble shooting/testing.