3.07 Nested Conditionals HW
3.07 Nested Conditionals Homework
POPCORN HACK 1
Code Runner Challenge
POPCORN HACK 1
View IPYNB Source
# CODE_RUNNER: POPCORN HACK 1
is_weekday = True
homework_finished = False
if is_weekday:
if homework_finished:
print("Free time")
else:
print("Finish homework")
else:
print("Weekend plan")
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
POPCORN HACK 2
Code Runner Challenge
POPCORN HACK 2
View IPYNB Source
# CODE_RUNNER: POPCORN HACK 2
logged_in = True
has_permission = False
if logged_in:
print("Account found")
if has_permission:
print("Page opened")
else:
print("Permission needed")
else:
print("Log in first")
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
POPCORN HACK 3
Code Runner Challenge
POPCORN HACK 3
View IPYNB Source
# CODE_RUNNER: POPCORN HACK 3
lunch_packed = True
practice_after_school = True
if lunch_packed:
if practice_after_school:
print("Packed lunch ready. Bring an extra snack for practice.")
else:
print("Packed lunch ready. No extra snack needed today.")
else:
if practice_after_school:
print("Buy lunch and save money for an after-practice snack.")
else:
print("Buy lunch. Head home after school.")
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
Compact Decision Tree
HOMEWORK HACK
Code Runner Challenge
HOMEWORK HACK
View IPYNB Source
# CODE_RUNNER: HOMEWORK HACK
student = {
"logged_in": True,
"homework_finished": False,
"lunch_packed": True,
"practice_today": True
}
if student["logged_in"]:
print("Dashboard opened")
if student["homework_finished"]:
if student["lunch_packed"]:
if student["practice_today"]:
print("Homework done. Bring your packed lunch and an extra snack for practice.")
else:
print("Homework done. Bring your packed lunch and enjoy free time after school.")
else:
if student["practice_today"]:
print("Homework done. Buy lunch and save money for an after-practice snack.")
else:
print("Homework done. Buy lunch and head home after school.")
else:
print("Finish homework before choosing dinner, sports, or free time.")
else:
print("Log in first")
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...
HOMEWORK TESTS
Code Runner Challenge
HOMEWORK TESTS
View IPYNB Source
# CODE_RUNNER: HOMEWORK TESTS
test_students = [
{"logged_in": False, "homework_finished": True, "lunch_packed": True, "practice_today": True},
{"logged_in": True, "homework_finished": False, "lunch_packed": True, "practice_today": True},
{"logged_in": True, "homework_finished": True, "lunch_packed": True, "practice_today": True},
{"logged_in": True, "homework_finished": True, "lunch_packed": True, "practice_today": False},
{"logged_in": True, "homework_finished": True, "lunch_packed": False, "practice_today": True},
{"logged_in": True, "homework_finished": True, "lunch_packed": False, "practice_today": False}
]
for student in test_students:
print("Test:", student)
if student["logged_in"]:
print("Dashboard opened")
if student["homework_finished"]:
if student["lunch_packed"]:
if student["practice_today"]:
print("Homework done. Bring your packed lunch and an extra snack for practice.")
else:
print("Homework done. Bring your packed lunch and enjoy free time after school.")
else:
if student["practice_today"]:
print("Homework done. Buy lunch and save money for an after-practice snack.")
else:
print("Homework done. Buy lunch and head home after school.")
else:
print("Finish homework before choosing dinner, sports, or free time.")
else:
print("Log in first")
print("---")
Lines: 1
Characters: 0
Output
Click "Run" in code control panel to see output ...