Scratch if and if-else blocks as Python if/else

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

Scratch if and if-else blocks as Python if/else

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A Scratch if block has the hexagon condition (score = 10). Which Python line matches it?
A if score = 10:
B if score == 10:
2. In Scratch, the blocks inside an if block are tucked into the C shape. How does Python show they belong to the if?
A They are indented lines under the if line
B They are written in curly brackets { }
3. Which line is the Python version of the 'else' part of a Scratch if-else block?
A else:
B else
4. The Scratch hexagon says (age > 12). What does this become in Python?
A if age > 12:
B if (age > 12) then
5. Which Python code is correct for an if-else block that says 'Win!' or 'Try again'?
A if score == 10: print('Win!') else: print('Try again')
B if score == 10: print('Win!') else: print('Try again')

Match the Pairs

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

Left columnRight column
1if score == 10: Aif answer == 5:
2else: BThe colon is missing at the end of the if line. Python needs it where the Scratch block opens.
3The blocks inside a Scratch if block become lines indented under the if line CA single = is used for the Scratch equals check, but Python needs == to compare two values. A single = is for assignment.
4The Scratch = in a hexagon checks if two things are equal, so Python uses == in the comparison Dif lives == 0: print("Game over")
5if score = 10: EThe 'else' part of a Scratch if-else block, followed by a colon and indented lines for the blocks inside
6if score == 10 print("Win") FThe Scratch block 'if score = 10 then' written in Python: the hexagon becomes a comparison, followed by a colon

Definitions

if score == 10:

Fill in the Blanks

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

1.
__ score == 10: print("You win!")
2.
if score __ 10: print("You win!")
3.
if score == 10: print("Win") ____:
4.
if age __ 13: print("Teen") else:
5.
if score == 10: _____("You win!") else:

Spot the Error

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

Question 1
A score = 10
B print("Checking score")
C if score = 10:
D print("Perfect!")
Question 2
A age = 13
B print("Checking age")
C if age >= 13
D print("Teen")
Question 3
A score = 7
B if score == 10:
C print("Win")
D else
E print("Try again")
Question 4
A lives = 0
B print("Lives left")
C if lives == 0 then:
D print("Game over")
Question 5
A answer = input("Ready? ")
B If answer == "yes":
C print("Go!")
D else:
E print("Wait")

Answer Key

Scratch if and if-else blocks as Python if/else
Section A: Quick Questions
Q1
B — if score == 10:
Q2
A — They are indented lines under the if line
Q3
A — else:
Q4
A — if age > 12:
Q5
B — if score == 10: print('Win!') else: print('Try again')
Section B: Match the Pairs
Q1
if score == 10: → The Scratch block 'if score = 10 then' written in Python: the hexagon becomes a comparison, followed by a colon
Q2
else: → The 'else' part of a Scratch if-else block, followed by a colon and indented lines for the blocks inside
Q3
The blocks inside a Scratch if block become lines indented under the if line → if lives == 0: print("Game over")
Q4
The Scratch = in a hexagon checks if two things are equal, so Python uses == in the comparison → if answer == 5:
Q5
if score = 10: → A single = is used for the Scratch equals check, but Python needs == to compare two values. A single = is for assignment.
Q6
if score == 10 print("Win") → The colon is missing at the end of the if line. Python needs it where the Scratch block opens.
Section C: Definitions
Q1
if score == 10: — Python's version of Scratch's if block: the hexagon condition becomes a comparison like ==, then a colon, and the blocks inside become indented lines. Add else: for the else part.
Section D: Fill in the Blanks
Q1
if score == 10: print("You win!")
Q2
if score == 10: print("You win!")
Q3
if score == 10: print("Win") else:
Q4
if age >= 13: print("Teen") else:
Q5
if score == 10: print("You win!") else:
Section E: Spot the Error
Q1
C — A single = stores a value in a variable. The Scratch = in the hexagon becomes == in Python, so it should be: if score == 10:
Q2
C — A Python if line must end with a colon, which starts the indented block. It should be: if age >= 13:
Q3
D — The else part of the Scratch if-else block becomes else: in Python. It needs a colon after it, so it should be: else:
Q4
C — Scratch blocks say 'then' but Python does not use that word. The condition is followed straight by a colon. It should be: if lives == 0:
Q5
B — Python keywords are case sensitive. The keyword must be lowercase: if answer == "yes":