Comparisons & Boolean Logic — Lesson 4: Build: Entry Check
New skill: Combining comparisons and logical operators
Previously learned: Unit 03 — parameters and return values
Why this matters
An event app can decide whether a person qualifies based on a pass or an age threshold.
Study this example
def can_watch(age, has_ticket):
return age >= 13 and has_ticket
The comparison age >= 13 returns a Boolean. and combines that with the second Boolean parameter.
Before moving on, trace each line of the example by hand. Predict the result before running it in the browser.
Check your understanding
Does the sample function allow a twelve-year-old with a ticket?
Common mistake
Be explicit about whether the rule requires both conditions or only one.
Practice: Build: Entry Check
Complete can_enter_event(has_pass, age) so entry is allowed (True) if the person has a pass or is at least 18 years old. Otherwise return False.
Example 1 — Input
can_enter_event(True, 12)
Output
True
Example 2 — Input
can_enter_event(False, 18)
Output
True
Example 3 — Input
can_enter_event(False, 17)
Output
False
Example 4 — Input
can_enter_event(False, 35)
Output
True
Starter file: main.py
Use Run to experiment and Check to compare against published examples. A passing public example does not automatically establish mastery.
Hint 1 — Identify the key concept
Identify the two ways a person can qualify.Hint 2 — Find an approach
Age must be compared to 18, including 18 itself.Hint 3 — Check your answer
Join the two qualification conditions using `or`.Reflection
Write a short explanation of why your code works. What input or change would make it behave differently?