Here's a script that explains who is allowed into the waterpark based on the provided rules. The output is organized according to the logical structure you provided:
def check_entry(age, has_adult, with_school_group, has_waiver):
# Define the conditions
p = age > 21 # Is over 21
q = age > 16 # Is over 16
r = age < 21 # Is under 21
s = has_adult # Has an adult with them
t = with_school_group # Is with a school group
u = has_waiver # Has a waiver
# Check the entry conditions
if p:
return "Allowed: You are over 21 years old."
elif q and u:
return "Allowed: You are over 16 years old and have a waiver."
elif r and s:
return "Allowed: You are under 21 years old and have an adult with you."
elif r and t:
return "Allowed: You are under 21 years old and are with a school group."
else:
return "Not Allowed: You do not meet the entry requirements."
# Example usage:
age = 17
has_adult = True
with_school_group = False
has_waiver = False
print(check_entry(age, has_adult, with_school_group, has_waiver))
Output Explanation
- "Allowed: You are over 21 years old." - This is based on the condition where
p
is true (over 21). - "Allowed: You are over 16 years old and have a waiver." - This results from the condition where
q
(over 16) andu
(has a waiver) are both true. - "Allowed: You are under 21 years old and have an adult with you." - This comes from
r
(under 21) ands
(has an adult) being true. - "Allowed: You are under 21 years old and are with a school group." - This stems from
r
(under 21) andt
(with a school group) being true. - "Not Allowed: You do not meet the entry requirements." - This is the fallback message when none of the conditions are satisfied.
This structure accommodates the logical flow you requested, matching the rules in the order specified.