Scenario: A theme park needs a ticket program. Guests type their age and height in centimetres.
Ticket prices
- Under 5 years: free (print
Free entry) - Age 5 to 12: £15
- Age 13 to 64: £25
- Age 65 or over: £12
Ride rule
The big roller coaster needs age 12 or over and height 140 cm or more.
Your tasks
- Ask for age (integer) and height in cm (integer).
- Print the correct ticket message using
if/elif/else. - Then check the roller coaster rule with
and. Print eitherYou can ride the roller coasterorSorry, not tall or old enough for the roller coaster.
⚠️ Check the bigger age groups carefully. Put the under-5 check first.
💡 Try the whole challenge in your editor first. Only reveal the solution when you have had a proper go.
Solution
age = int(input("Enter your age: "))
height = int(input("Enter your height in cm: "))
# Ticket price
if age < 5:
print("Free entry")
elif age <= 12:
print("Ticket price: £15")
elif age <= 64:
print("Ticket price: £25")
else:
print("Ticket price: £12")
# Roller coaster check
if age >= 12 and height >= 140:
print("You can ride the roller coaster")
else:
print("Sorry, not tall or old enough for the roller coaster")
Example output:
Enter your age: 14
Enter your height in cm: 145
Ticket price: £25
You can ride the roller coaster