Ms. Whitby's Classroom logo Ms. Whitby's Classroom

Conditional Execution — Lesson 4: Build: Event Ticket Classifier

New skill: Conditionals and Boolean logic together
Previously learned: Unit 04 — comparisons and Boolean logic

Why this matters

A student event app classifies each ticket request using more than one condition.

Study this example

def category(age, vip):
    if vip:
        return 'Priority'
    elif age < 13:
        return 'Junior'
    else:
        return 'General'

Priority comes first, so it applies even if the guest is also younger than 13. The order of the checks communicates the intended rule.

Before moving on, predict the result of the program or function. Then run it and compare.

Check your understanding

Why does category(10, True) return ‘Priority’?

Common mistake

Do not test the age band before the VIP condition if priority must take precedence.

Practice

Complete classify_ticket(age, has_pass) to return 'Member' if has_pass is true, otherwise 'Youth' if age is under 18, otherwise 'Guest'. Return a string in every case.

Public example 1

Input

classify_ticket(15, True)

Output

'Member'

Public example 2

Input

classify_ticket(15, False)

Output

'Youth'

Public example 3

Input

classify_ticket(18, False)

Output

'Guest'

Public example 4

Input

classify_ticket(30, True)

Output

'Member'

Open the Python starter

Hint 1 Check the pass before classifying by age.
Hint 2 An age of 18 belongs to the Guest branch.
Hint 3 Use if / elif / else to select one exact label.

Reflection

Explain why your solution works and describe one boundary case you tried.