Fall 2024 - P2
Big Idea 3 | .1 | .2 | .3 | .4 | .5 | .6 | .7 | .8 | .10 |
3.7.2 Nested Conditionals Homework Hack
Student led teaching on Conditionals using Javascript and Python
Homework Hack
Directions:
Task List:
- Get Age: Prompt the user to enter their age.
- Check Ball Ownership: Ask if they have a ball (yes/no).
- Check Eligibility: Verify if they are at least 5 years old and have a ball.
- Determine Group: Assign a play group based on age (under 8 or 8 and older).
- Display Result: Print whether they can join the game and their group.
Solution:
# Input age and whether the child has a ball
age = int(input("Enter your age: "))
has_ball = input("Do you have a ball? (yes/no): ").lower()
# Check if the child can join the game
can_join_game = age >= 5 and has_ball == "yes"
if can_join_game:
if age < 8:
message = "You can play with the younger kids."
else:
message = "You can play with the older kids."
print(f"Great! {message}")
else:
print("Sorry, you can't join the game yet.")
Sorry, you can't join the game yet.