Everything from Week 3 in one program: build a ticket-price calculator that reads the customer’s age and the day of the week, then charges the right price. All conditionals, no new syntax.
No reading — build. Keep 2.13 (elif chains) and 2.14 (and / or) open in other tabs. You’ll use both today.
End of Week 3 in Programs. You put the whole week of
decisions together into one working program — input, an elif chain, and (for the
Challenge) a compound condition. This is also a Create PT rehearsal: a purpose, a decision, and
a precise sentence about your process.
Write a Python program that asks for a customer’s age and the day of the week, then prints the ticket price using these rules:
□ Under 5: free ($0).
□ Ages 5–12 (child): $8.
□ Ages 13–64 (adult): $12.
□ 65 and up (senior): $9.
□ Tuesday is $2 off any price that isn’t already free.
□ A purpose sentence comment at the top.
□ Read age with input() and convert with int() (2.4).
□ Use an elif chain for the age brackets — highest-priority conditions first.
□ Apply the Tuesday discount with a separate if.
□ Print the final price in a clear sentence with an f-string (2.7).
Copy the shape, not the numbers — then fill in the rules yourself:
# Prints a ticket price from age and day # so the box office can charge correctly. age = int(input("Age? ")) day = input("Day? ") if age < 5: price = 0 elif age <= 12: price = 8 elif age <= 64: price = 12 else: price = 9 if day == "Tue" and price > 0: price = price - 2 print(f"Price: ${price}")
# purpose: what + why # # age is a number → int() # day stays text # elif chain, highest # priority (free) first # child # # adult band # # everything left = senior # # compound condition: # Tuesday AND not already free # f-string output
Hover or tap a line to light its twin. Notice line 11: the discount uses an
and so a free toddler ticket never goes to -$2. That guard is the kind of
detail graders look for.
Run your rules against this before you trust your code. Set an age and a day; it shows the price your program should print. If yours disagrees, you found a bug.
□ The working program (reads age and day, prints the correct price).
□ Your purpose sentence at the top of the file.
□ One sentence naming a test you ran — an input you tried and the price you expected — and whether it matched. (“I tested age 4 on Tuesday and expected $0; it printed $0.”)
That test sentence is 2.16 arriving early: real programmers decide what the right answer is before running, then check. It’s also Create PT written-response practice.
Get the four age bands working and printing a price before you add the Tuesday discount. A program that does one thing correctly beats one that half-does two. Test each band as you add it: an age in the middle, then the exact boundary (is 12 a child or an adult in your code?).
If you pair, swap driver and navigator every 10 minutes as in 2.10.
Both of you must be able to explain why the discount uses and.
Real box-office software can’t trust its input. Add a check at
the top: if the age is negative or absurdly large (say over 120), print a clear
error instead of a price. That’s a compound condition —
if age < 0 or age > 120: — straight from 2.14.
Bigger challenge: swap the theme to a heat-index or
BMI classifier — read two numbers and sort the result into
safe/caution/danger bands with an elif chain. Same skill, different story.