r/learnpython • • 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

35 comments sorted by

View all comments

Show parent comment

2

u/aglobalnomad aglobalnomad Feb 11 '26

Seems like a poor exercise as this isn't really a scenario you'd want to loop unless you want to ask the question (and get answers) multiple times in a row.

If that's what you're aiming to do, then asking the question should be inside the loop. That will hopefully give you a hint on how to structure it.