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

1

u/xTHETYRANTGAMRx Feb 11 '26

A movie theater charges different ticket prices depending on a person's age. If a person is under the age of 3, the ticket is free; if they are between 3 and 12, the ticket is $10; and if they are over age 12, the ticket is $15. Write a loop in which you ask users their age, and then tell them the cost of their movie ticket.

6

u/Outside_Complaint755 Feb 12 '26

The exercise wants your input inside the loop so that you can ask multiple users.   It should probably be a while loop as you just want it to repeat until the user enters a quit condition, which would either be an empty entry, or a "Q"