South Plantation High School logo
South Plantation High School · Procedural Programming with Python

Deeply Nested Conditionals

nested if statements 2 to 4 levels deep · and · or · not · 20 items · submit as a PDF

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)

Error messages you may see in the terminal

How this works

  1. Enter your first name, last name initial, and class period, then click Start Assignment. Your start time is recorded.
  2. 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.
  3. 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.
  4. 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)

  1. After you click Submit for Score, click the Save as PDF button at the bottom of your results.
  2. In the print window, set Destination to Save as PDF (not a printer), then click Save.
  3. Keep the file name it suggests. It already has your name and period, for example Deep_Nested_Conditionals_Maria_R_P3.pdf.
  4. 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.

PartTaskItemsPoints
1Complex conditions inside nests that are 3 and 4 levels deep1 to 55
2Build deep nests: else / elif, and the right number of spaces at each level6 to 105
3Debug: fix the condition at levels 2 to 411 to 155
4Predict the output of 3 and 4 level programs16 to 205
Total (1 point per item)2020

Student Information

Reminder: nothing on this page is saved. Once you click Start Assignment, plan to finish before you leave or refresh the page.