Turning a flowchart into Python

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

Turning a flowchart into Python

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A flowchart has a diamond that asks 'Is age >= 13?' with a Yes path and a No path, and no arrows going back. Which Python keyword does the diamond become?
A if
B while
2. A flowchart has a diamond 'Is count < 5?'. The Yes path goes to a rectangle, then an arrow loops back up to the diamond. Which keyword does it become?
A while
B if
3. A flowchart has a parallelogram that says 'Get name from user'. Which Python code matches it?
A name = 'Name? '
B name = input('Name? ')
4. A flowchart has a parallelogram that says 'Show score'. Which Python code matches it?
A print(score)
B score = input()
5. A flowchart has a rectangle that says 'total = total + 5'. What does it become in Python?
A if total + 5:
B total = total + 5

Match the Pairs

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

Left columnRight column
1if age >= 13: AA diamond asking 'Is lives more than 0?' where an arrow loops back to it from the Yes path
2while lives > 0: Bscore = score + 1
3A parallelogram that says 'Input name' becomes an input() call CA diamond asking a question like 'Is age 13 or more?' where the flow only goes forward
4A rectangle that says 'Add 1 to score' becomes a statement Dname = input('Name? ')
5if count < 5: count = count + 1 (flowchart has a back arrow to the diamond) EThe flowchart has an arrow looping back to the diamond, so it needs a while loop, not an if. An if only checks once.
6while x > 10: print('Big') (flowchart diamond has no back arrow) FThe diamond has no arrow looping back, so it is a one-time decision. It should be an if, not a while.

Definitions

if / while

Fill in the Blanks

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

1.
__ age >= 13: print("Teen")
2.
_____ count < 5: count = count + 1
3.
name = _____("Name? ") print(name)
4.
score = 10 _____(score)
5.
while lives > 0: print("Playing") lives = lives _ 1

Spot the Error

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

Question 1
A age = int(input('Age: '))
B if age >= 13
C print('Teen')
Question 2
A count = 1
B while count <= 3:
C print(count)
D count + 1
Question 3
A score = int(input('Score: '))
B while score > 50:
C print('Pass')
Question 4
A num = input('Number: ')
B num = int(num)
C input(num * 2)
Question 5
A pin = print('PIN: ')
B if pin == '1234':
C print('Open')
D else:
E print('Locked')

Answer Key

Turning a flowchart into Python
Section A: Quick Questions
Q1
A — if
Q2
A — while
Q3
B — name = input('Name? ')
Q4
A — print(score)
Q5
B — total = total + 5
Section B: Match the Pairs
Q1
if age >= 13: → A diamond asking a question like 'Is age 13 or more?' where the flow only goes forward
Q2
while lives > 0: → A diamond asking 'Is lives more than 0?' where an arrow loops back to it from the Yes path
Q3
A parallelogram that says 'Input name' becomes an input() call → name = input('Name? ')
Q4
A rectangle that says 'Add 1 to score' becomes a statement → score = score + 1
Q5
if count < 5: count = count + 1 (flowchart has a back arrow to the diamond) → The flowchart has an arrow looping back to the diamond, so it needs a while loop, not an if. An if only checks once.
Q6
while x > 10: print('Big') (flowchart diamond has no back arrow) → The diamond has no arrow looping back, so it is a one-time decision. It should be an if, not a while.
Section C: Definitions
Q1
if / while — A flowchart diamond (a decision) becomes if, or while when an arrow loops back to it. Rectangles become statements and parallelograms become input() or print().
Section D: Fill in the Blanks
Q1
if age >= 13: print("Teen")
Q2
while count < 5: count = count + 1
Q3
name = input("Name? ") print(name)
Q4
score = 10 print(score)
Q5
while lives > 0: print("Playing") lives = lives - 1
Section E: Spot the Error
Q1
B — The decision diamond becomes an if statement, and every if line must end with a colon. It should be: if age >= 13:
Q2
D — The rectangle that adds 1 must be a statement that stores the answer. 'count + 1' works it out but does not save it, so count never changes and the loop never ends. It should be: count = count + 1
Q3
B — This diamond has no arrow looping back to it, so it is a single decision. It should be: if score > 50:, not a while loop.
Q4
C — A parallelogram that shows a result becomes print(). input() is only for getting a value from the user. It should be: print(num * 2)
Q5
A — A parallelogram that asks the user for a value becomes input(). It should be: pin = input('PIN: ')