Instructions
The information on this page is not stored. If you start an assignment, you must finish it. This page does not save your progress.
Quick review
Complex Boolean expressions
age >= 13 and age <= 19 # both True day == "Sat" or day == "Sun" # at least one not is_raining # flips it
Multiple if statements
if temp < 50:
print("jacket")
if is_raining:
print("umbrella")
Nested if statements
if has_key:
if level >= 5:
print("Door opens")
else:
print("Level up")
else:
print("Find the key")
andis True only when both sides are True.oris True when at least one side is True.notflips True and False.- Order of operations: parentheses, then math, then comparisons, then
not, thenand, thenor. Use parentheses to group parts that belong together. - Write a complete comparison on each side:
color == "red" or color == "blue", notcolor == "red" or "blue". Andage >= 13 and age <= 19, notage >= 13 and <= 19. - Separate
ifstatements are all checked, so several can run. Anif-elif-elsechain runs only the first True branch. - In a nested
if, the innerifis only checked when the outer condition is True. Each level adds 4 more spaces, and eachelsebelongs to theifit lines up with.
Error messages you may see in the terminal
SyntaxError: invalid syntaxcan mean half a comparison (x >= 1 and <= 10), orAND,&&, or||instead ofand/or.IndentationError: expected an indented block after 'if' statement on line 5means the line after anifis not indented further.IndentationError: unindent does not match any outer indentation levelmeans anelse(or another line) does not line up with any level above it.- No error at all is possible too! The
ortrap and missing parentheses run 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 practice item. There are 30 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, so you can check your predictions. 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.
| Part | Task | Items | Points |
|---|---|---|---|
| 1 | Complex Boolean expressions: and, or, not, ranges, the or trap, and parentheses | 1 to 8 | 8 |
| 2 | Multiple if statements: separate ifs vs. one elif chain | 9 to 15 | 7 |
| 3 | Nested if statements: indentation, inner chains, and rewriting with and | 16 to 23 | 8 |
| 4 | Predict the output of expressions and nested code | 24 to 30 | 7 |
| Total (1 point per item) | 30 | 30 |
Student Information
Items answered: 0 of 30
Task: Each program has a comment that says what it should do. Complete every numbered box and drop down.
- Items 5 and 7 already have code in them, but the code has a bug. Fix it.
- Items 6 and 8: write the whole condition or the whole
ifline yourself.
Can go
Weekend!
Stay inside
Teen
Primary color
Out of range
Enjoy the ride!
Discount
Task: Decide when to use separate
if statements (more than one can run) and when to use an elif chain (only one can run).
- Item 14: type what goes after
passed =so it adds one to the count. - Item 15: write the whole
ifline yourself.
Bring:
- jacket
- umbrella
Fee: 6
Century badge
Streak badge
Super badge
Passed: 2
Study more
Task: Complete each nested
if. Watch the indentation: each level adds 4 spaces, and an else belongs to the if it lines up with.
- Items 16 and 21 already have code in them, but the indentation is wrong. Fix the spaces at the start.
- Item 22: write one
ifline that does the same job as the nested code in the comment.
Welcome!
Side door opens
Enjoy the movie
Not positive
Honor roll
No school today
Task: Trace each small program in your head and choose what it prints.
- Items 24 to 26: work out each Boolean expression step by step. Remember the order: comparisons,
not,and, thenor. - Items 27 to 30: follow the
ifstatements line by line. Watch the indentation.
TerminalProblemsOutput