This assignment has not been submitted. Click Submit for Score first, then click Save as PDF on the results.
Instructions
The information on this page is not stored. If you start an assignment, you must finish it. To get a grade, you must save your results as a PDF and turn it in (steps are below).
Quick review
Complex Boolean expressions (two conditions)
age >= 13 and age <= 19 # both must be True day == "Sat" or day == "Sun" # at least one True not is_raining and temp > 70 # not flips one side
Nested if (two levels)
if has_ticket: # level 1
if age >= 13: # level 2
print("Enjoy!")
else:
print("Pick another")
else:
print("Buy a ticket")
Nested if with a complex condition
if is_member:
if paid and not banned:
print("Come in")
else:
print("See the desk")
elif guest_pass:
print("Guest entry")
andis True only when both conditions are True.oris True when at least one is True.notflips True and False.- Every condition in this assignment joins no more than two comparisons, and every nested
ifgoes no more than two levels deep. - Write a complete comparison on each side:
team == "red" or team == "blue", notteam == "red" or "blue"(the or trap, which is always True). - The inner
ifis only checked when the outer condition is True. Level 1 code is indented 4 spaces, level 2 code is indented 8 spaces. - An
elseorelifbelongs to theifit lines up with.
Error messages you may see in the terminal
SyntaxError: invalid syntaxcan mean half a comparison (age >= 13 and <= 19), orAND,&&, or||instead ofand/or.SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?means you used=where a comparison needs==.IndentationError: expected an indented block after 'if' statementmeans the line after anifis not indented further.- No error at all is possible too! The or trap and the wrong
and/orrun without an error but give the wrong answer. Compare your output with the expected output.
How this works
- Enter your first name, last name initial, and class period, then click Start Assignment. Your start time is recorded.
- The assignment opens in a Python editor with four files (tabs). Each orange numbered box or drop down is one item. There are 20 items.
- Click ▶ Run on any part to see what Python prints. On Parts 1 to 3, compare it with the expected output. On Part 4, Run shows what each small program prints. Run does not grade you, so check your work carefully.
- When you finish all four tabs, click Submit for Score. Your end time is recorded and your score appears. Answers cannot be changed after submitting.
Turning it in: save a PDF (required for a grade)
- After you click Submit for Score, click the Save as PDF button at the bottom of your results.
- In the print window, set Destination to Save as PDF (not a printer), then click Save.
- Keep the file name it suggests. It already has your name and period, for example
Nested_Conditionals_Maria_R_P3.pdf. - Turn in the PDF where your teacher tells you to.
Do not refresh or close the page until your PDF is saved. Nothing is stored, so if you leave first you will have to do the assignment again. The PDF shows your name, period, times, score, every answer, and your completed code.
| Part | Task | Items | Points |
|---|---|---|---|
| 1 | Build complex conditions with and, or, not inside nested ifs | 1 to 5 | 5 |
| 2 | Complete nested if / elif / else structures and fix their indentation | 6 to 10 | 5 |
| 3 | Debug: fix the complex condition in each nested if | 11 to 15 | 5 |
| 4 | Predict the output of nested code | 16 to 20 | 5 |
| Total (1 point per item) | 20 | 20 |
Student Information
Items answered: 0 of 20
Task: Each program has a comment that says what it should do. Choose the right logical operator, or type the condition.
- Item 4: type the whole condition (two comparisons joined with
andoror). - Item 5: type the whole inner
ifline. The 4 spaces in front are already there.
Pack your lunch!
Beach day!
Teen hours: come in!
Snow day!
Task: Complete each nested
if / elif / else. Watch which if each branch lines up with.
- Items 9 and 10 already have code in them, but the indentation is wrong. Fix the spaces at the start of the line.
A with honors
Price: 8
Access granted
Charging
Task: Every inner condition has one bug. Some cause an error, and some run but give the wrong answer. Fix each condition so the program does what the comment says. Keep it to two comparisons or fewer.
No jersey for your team yet
Sleep in
Teen discount applied
Ready to graduate
Enjoy your book
Task: Trace each small program in your head and choose what it prints. Work out each condition step by step, and watch the indentation to see which
if each else belongs to.TerminalProblemsOutput