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

Python Logic & Structure Practice

Instructions · Comments · Indentation

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.

1. Instructions run from top to bottom

A Python program is a list of instructions. Python runs them one at a time, from the top line to the bottom line. Each instruction goes on its own line.

print("First")     # runs 1st
print("Second")    # runs 2nd
print("Third")     # runs 3rd

Because Python reads from the top down, a variable must be created before you use it.

Correct order
name = "Ava"
print(name)    # prints Ava
Wrong order
print(name)    # Error! name does not exist yet
name = "Ava"

Two more rules for writing instructions:

2. Comments

A comment starts with #. Python ignores everything from the # to the end of that line. Programmers use comments to explain code to people.

3. Indentation

Indentation means spaces at the start of a line. Python pays close attention to these spaces. Later in the course you will learn when to indent. For now, the rule is simple: every line starts at the left edge, with no spaces in front.

On this page, each orange dot · stands for one space.

Correct
name = "Ava"
print(name)
IndentationError
name = "Ava"
··print(name)    # 2 extra spaces

Spaces in the middle of a line, like x = 5, do not cause an error. Only spaces at the start do. (Style tip: one space on each side of =, like x = 5, is easiest to read.)

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). Complete every orange dashed box and drop down.
  3. Click ▶ Run on any part to see what Python would print in the terminal. 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.
PartTaskPoints
1Instructions: put lines in the right order and fix two broken lines8
2Comments: decide what Python runs or ignores, then write comments8
3Indentation: spot the lines that cause an error5
4Indentation: fix a program by removing extra spaces4
Total25

Student Information

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