← Back to Blog

IF Mini Project — Your ticket, your price

The problem...

You know how to make a decision. You know how to chain conditions with elif.

But real programs rarely make just one decision. They check multiple things — and combine them.

Time to build something that does exactly that.

The idea!

A ticket pricing system. Simple, real, something you've encountered a hundred times without thinking about it.

The price depends on who you are. And where you want to sit.

Your mission

Build a ticket pricing system. The user enters their age and whether they want a window seat. Your program calculates the final price.

Base price by age:

  • Under 12 — child — 5 EUR
  • 12 to 64 — adult — 12 EUR
  • 65 and above — senior — 8 EUR

Window seat — adults only — +3 EUR

New operator — and

Sometimes one condition isn't enough. You need two things to be true at the same time.

if window == "y" and age >= 12:
    price += 3

Both must be true for the block to run. If either one is false — it's skipped.

One more thing — +=

price += 3 is shorthand. It means: take the current value of price and add 3 to it.

price = 12
price += 3
print(price)    # 15

Same as writing price = price + 3. Just cleaner.

The solution

age = int(input("Enter your age: "))
window = input("Window seat? (y/n): ")

if age < 12:
    price = 5
    category = "Child"
elif age >= 65:
    price = 8
    category = "Senior"
else:
    price = 12
    category = "Adult"

if window == "y" and age >= 12:
    price += 3

print(f"{category} ticket — {price} EUR")

Test it

# Age: 8,  window: y  -->  Child ticket — 5 EUR
# Age: 30, window: n  -->  Adult ticket — 12 EUR
# Age: 30, window: y  -->  Adult ticket — 15 EUR
# Age: 70, window: y  -->  Senior ticket — 8 EUR

Notice the last one — seniors don't pay extra for the window. One condition took care of that.

What's really happening

Two separate decisions. First your program decides the category. Then it checks the seat. The final price is the result of both.

That's how real systems work — not one giant condition, but clean decisions stacked together.

Go further

  • Add a student category — age 12 to 25, 8 EUR
  • Add a weekend surcharge — ask the user if it's a weekend, +2 EUR for adults
  • Print a full ticket summary — category, seat type, and final price on separate lines

What you should understand now

  • if / elif / else handles the base decision — category and price
  • and combines two conditions — both must be true for the block to run
  • Real programs make multiple decisions and combine the results
  • += adds to an existing value — price += 3 is the same as price = price + 3
[ login to bookmark ] // copied! 35 views · 2 min
// resources
Exercise ticket_pricing.py
← prev IF Mini Project — PACE, Your First Real Decision System next → Common IF Mistakes
// 0 comments
// No comments yet. Be the first.
// leave a comment

// Your comment will appear after approval.