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
Four levels deep
if power_on: # level 1
if battery >= 20: # level 2
if mode == "auto": # level 3
if room == "den": # level 4
print("Clean")
else:
print("Skip")
Count the spaces
# Each level adds 4 spaces. # The code INSIDE an if at # level 1 starts at 4 spaces # level 2 starts at 8 spaces # level 3 starts at 12 spaces # level 4 starts at 16 spaces
Complex conditions at any level
if has_ticket:
if age >= 18 or with_parent:
if not sold_out:
print("Enjoy the show")
# Parentheses group parts:
# weekend and (sunny or warm)
- Trace from the top. Python only goes into an
ifwhen its condition is True. If it is False, Python skips everything indented under it, no matter how deep, and jumps to the matchingelif/else. - An
elseorelifbelongs to theifit lines up with. Line up your finger with theelseand move straight up until you hit anif. That is its partner. andis True only when both sides are True.oris True when at least one is True.notflips True and False. Python doesnotfirst, thenand, thenor, so use parentheses to group anorthat belongs together.- Write a complete comparison on each side:
size == "small" or size == "medium", notsize == "small" or "medium"(the or trap).
Error messages you may see in the terminal
IndentationError: expected an indented block after 'if' statement on line 7means the line after anifis not indented further than theif.IndentationError: unindent does not match any outer indentation levelmeans a line does not line up with any level above it. Use exactly 4 spaces per level.SyntaxError: invalid syntaxon anelsecan mean thatifalready has anelse, so thiselseis lined up with the wrongif. It can also mean half a comparison, likehour >= 9 and < 17.- No error at all is possible too! The or trap,
andvs.or,>vs.>=, and missing parentheses all run 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
Deep_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 | Complex conditions inside nests that are 3 and 4 levels deep | 1 to 5 | 5 |
| 2 | Build deep nests: else / elif, and the right number of spaces at each level | 6 to 10 | 5 |
| 3 | Debug: fix the condition at levels 2 to 4 | 11 to 15 | 5 |
| 4 | Predict the output of 3 and 4 level programs | 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.
- Items 2 and 4: type the whole condition.
- Item 5: type the whole
ifline. The 8 spaces in front are already there.
Need a parent
3 stars
Practice outside
Pay the late fee
Task: Complete each nest. Count the levels: every level adds 4 spaces.
- Items 8 and 10 already have code in them, but the indentation is wrong. Fix the spaces at the start of the line.
- Item 9: type the whole
printline, including the spaces in front of it.
Full scholarship
Unlocked
Cleaning the kitchen
PG-13 with an adult
Task: Each condition in an orange box 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.
Free size is small or medium
Come on in
No payment needed
Ride free
Picnic another day
Task: Trace each program in your head and choose what it prints. Go one level at a time: if a condition is False, skip everything indented under it. Line up each
else with its if.TerminalProblemsOutput