Running a Python program

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Running a Python program

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is a Python program?
A A picture that Python draws on screen
B A text file of instructions that Python runs
2. Where do you write your Python instructions?
A In the editor
B In the output panel
3. Where do you see the words printed by print("Hi")?
A In the output panel
B In the editor
4. Which button makes Python start doing your instructions?
A Save as
B Run
5. In which order does Python run the lines of a program?
A From the first line to the last line
B From the last line to the first line

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1print("Hi") print("Bye") AThe program was written in the editor but never run. Python only does the instructions after you press Run.
2print("Hello") Bprint(1) print(2) print(3)
3Python runs a program one line at a time, starting at the first line and finishing at the last line CPython does not run the last line first. It runs from the first line to the last, so Hi shows before Bye.
4You write the instructions in the editor, and the results appear in the output panel after you press Run Dprint("Go!")
5print("Hi") print("Bye") # expected output: Bye then Hi EPython runs the lines in order, so the output panel shows Hi first and then Bye
6print("Score: 10") # I typed this but did not press Run # output panel is empty FA one-line program: when you press Run, the output panel shows Hello

Definitions

program

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
_____("Hello, world!")
2.
print("Ready") _____("Set") print("Go!")
3.
lives = 3 lives = lives - 1 print(_____)
4.
a = 2 b = a * 3 print(_)
5.
print(2 _ 3)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A print("Start")
B name = "Sam"
C print("Hi", Name)
Question 2
A prnt("Welcome")
B print("Press Run")
C print("Done")
Question 3
A print("Step 1")
B print("Step 2)
C print("Step 3")
Question 4
A score == 10
B score = score + 5
C print(score)
Question 5
A print("Loading...")
B print "Ready!"
C print("Go")

Answer Key

Running a Python program
Section A: Quick Questions
Q1
B — A text file of instructions that Python runs
Q2
A — In the editor
Q3
A — In the output panel
Q4
B — Run
Q5
A — From the first line to the last line
Section B: Match the Pairs
Q1
print("Hi") print("Bye") → Python runs the lines in order, so the output panel shows Hi first and then Bye
Q2
print("Hello") → A one-line program: when you press Run, the output panel shows Hello
Q3
Python runs a program one line at a time, starting at the first line and finishing at the last line → print(1) print(2) print(3)
Q4
You write the instructions in the editor, and the results appear in the output panel after you press Run → print("Go!")
Q5
print("Hi") print("Bye") # expected output: Bye then Hi → Python does not run the last line first. It runs from the first line to the last, so Hi shows before Bye.
Q6
print("Score: 10") # I typed this but did not press Run # output panel is empty → The program was written in the editor but never run. Python only does the instructions after you press Run.
Section C: Definitions
Q1
program — A text file of Python instructions. You write it in the editor, and when you press Run, Python does each line in order from first to last and shows the output in the output panel.
Section D: Fill in the Blanks
Q1
print("Hello, world!")
Q2
print("Ready") print("Set") print("Go!")
Q3
lives = 3 lives = lives - 1 print(lives)
Q4
a = 2 b = a * 3 print(b)
Q5
print(2 + 3)
Section E: Spot the Error
Q1
C — Python cares about capital letters. The variable was made as name (lowercase), so Name causes an error when you press Run. It should be print("Hi", name).
Q2
A — print is spelled wrong. Python runs line 1 first and stops with an error because it does not know prnt. It should be print("Welcome").
Q3
B — The text is missing its closing quote. Python cannot finish reading the string, so it shows a syntax error. It should be print("Step 2").
Q4
A — A double equals sign compares values. It does not store one. Python runs line 1 first, so score is never created. Use a single = like score = 10.
Q5
B — In Python 3, print needs brackets around what it shows. Without them Python gives a syntax error. It should be print("Ready!").