Year 7 · Y7.3 Introduction to Python · Lesson 3
Stretch tasks Making decisions
Quiz Challenge
A quiz game against four computer players, then short and long written answers.
- Quiz Blitz12 questions against the clock
- Quick Fire4 short answers
- Big Think2 long answers
About 20 minutes
This or That
Pixel the cat asks 8 questions. Each has two answers: pick the right one.
- Two answers to every question
- A fish treat for every right answer
- Streaks win Pixel shades, then a party hat
About 4 minutes
Memory Match
Flip the cards two at a time to match each operator card to its meaning card.
- 12 cards: each operator has a meaning
- One peek at every card
- Combo points for pairs found in a row
6 pairs, about 4 minutes
The games need JavaScript. Every question is below, with the answers at the end.
Read the lesson: Making decisions
Making decisions: the questions
Quiz Challenge, round 1: Quiz Blitz
age is 13. What is printed?
if age >= 13: print("You can have an account") else: print("You are too young")- You are too young
- An error
- Nothing
- You can have an account
What must go at the end of an if line?
- A semicolon ;
- A full stop .
- Nothing
- A colon :
Which operator means is not equal to?
!===<>=!
= and == do the same job.
- True
- False
mark is 95. What is printed?
if mark >= 30: print("Keep working") elif mark >= 70: print("Excellent")- Nothing
- Keep working
- Excellent
- Keep working, then Excellent
mark is 55. What is printed?
if mark >= 70: print("Excellent") elif mark >= 50: print("Good") elif mark >= 30: print("Keep working") else: print("See your teacher")- Excellent
- Keep working
- See your teacher
- Good
Which error do you get if the lines under an if are not indented?
- NameError
- IndentationError
- ValueError
- TypeError
What does elif mean?
- either
- else if
- else
- end if
x is 5. Which TWO conditions are True?
Tick 2.
x >= 6x > 3x == 5x < 5x != 5
Put these in the order they should be checked, for messages from Excellent down to See your teacher.
Number these 1 to 4.
elsemark >= 70mark >= 50mark >= 30
Which operator means is less than or equal to? Type it.
NameError: name 'scroe' is not defined. What is the most likely cause?
- A typo in the variable's name
- A missing colon
- Text added to a number
- Lines not indented
Quiz Challenge, round 2: Quick Fire
Give two things you must remember when writing an if statement in Python. [2 marks]
Explain the difference between = and ==. [2 marks]
Why should the most restrictive condition come first in an if ... elif chain? [2 marks]
What does SyntaxError: invalid syntax usually mean? [2 marks]
Quiz Challenge, round 3: Big Think
This program should print Excellent for 70 or more, but a mark of 95 prints Keep working. Explain the bug and how to fix it. [4 marks]
mark = 95 if mark >= 30: print("Keep working") elif mark >= 50: print("Good") elif mark >= 70: print("Excellent")Describe a program that asks for an age and says whether the person can have an account, which needs them to be 13 or over. Explain each part. [6 marks]
This or That: tick the right answer
Which line checks whether age is 13?
if age == 13:if age = 13:
What happens when an if line has no colon?
- It works anyway
- A SyntaxError
x is 7. What is printed?
if x > 10: print("Big") else: print("Small")- Big
- Small
How many branches of an if ... elif ... else chain run?
- Only the first true one
- Every true one
Which means is greater than or equal to?
>==>
TypeError: can only concatenate str. What went wrong?
- Text and a number were joined with +
- A colon is missing
Is 5 != 5 True or False?
- True
- False
Where should the most restrictive condition go?
- Last
- First
Memory Match: match each operator to its meaning
| Operator | Meaning |
|---|---|
A == | 1 is less than or equal to |
B != | 2 is greater than or equal to |
C < | 3 is greater than |
D > | 4 is equal to |
E <= | 5 is less than |
F >= | 6 is not equal to |
Answers
Round 1: Quiz Blitz
- You can have an account 13 >= 13 is true, so the if branch runs.
- A colon : Forgetting the colon gives a SyntaxError.
!=!= means is not equal to.- False One = puts a value into a variable. Two == compare two values.
- Keep working Python runs the first true condition and skips the rest. 95 >= 30 is true, so it never reaches the >= 70 test.
- Good 55 is not >= 70, but it is >= 50, so Good is printed and the rest are skipped.
- IndentationError The lines inside an if must be indented consistently, usually by four spaces.
- else if elif is short for else if: another condition to check when the ones before were false.
x > 3;x == 55 > 3 and 5 == 5 are true. 5 is not less than 5, and it is equal to 5.mark >= 70→mark >= 50→mark >= 30→elseMost restrictive first, so that every mark reaches the right message.- <= <= means is less than or equal to.
- A typo in the variable's name NameError usually means a variable was used before it was created, or its name has a typo.
Round 2: Quick Fire
- A colon at the end of the if line
- Indent the lines underneath
- Use == to compare, not =
Model answerPut a colon at the end of the if line, and indent the lines underneath by four spaces.
- = puts a value into a variable
- == compares two values to check whether they are equal
Model answerOne = puts a value into a variable. Two == compares two values to check whether they are equal.
- Python runs only the first true condition and skips the rest
- Otherwise a high mark matches a lower condition and gets the wrong message
Model answerPython stops at the first true condition and skips the rest. If mark >= 30 came first, a mark of 95 would print Keep working, so the right message would never be reached.
- A missing colon
- A missing bracket
Model answerIt usually means a missing colon at the end of an if line, or a missing bracket.
Round 3: Big Think
- Python runs the first condition that is true
- 95 >= 30 is true, so it prints Keep working
- The other conditions are never checked
- Fix: put the most restrictive condition, mark >= 70, first
- Then mark >= 50, then mark >= 30
Model answerPython checks the conditions in order and stops at the first one that is true. 95 >= 30 is true, so it prints Keep working and the other conditions are never checked. To fix it, put the most restrictive condition first: mark >= 70, then mark >= 50, then mark >= 30.
- input asks for the age
- int() converts it into a whole number
- The condition uses >=, greater than or equal to
- A colon ends the if line
- The lines underneath are indented
- An else branch handles anyone younger
- input gives text, which is why it must be converted
Model answerThe program uses input to ask for the age. input gives text, a string, so int() converts it into a whole number. Then an if statement checks the condition age >= 13, which means greater than or equal to 13, with a colon at the end of the line. The line underneath is indented by four spaces and says You can have an account. An else branch, also indented, says You are too young.
This or That
if age == 13:Comparing uses two equals signs. One = would be a SyntaxError here.- A SyntaxError Every if, elif and else line must end with a colon.
- Small 7 is not greater than 10, so the else branch runs.
- Only the first true one Python runs the first true condition, then skips the rest.
>=Python writes it as >=. => is not a comparison in Python.- Text and a number were joined with + Convert the number with str() before joining it to text.
- False != means not equal, and 5 is equal to 5.
- First Python stops at the first true condition, so the most restrictive one must be checked first.
Memory Match
- A 4
==: is equal to - B 6
!=: is not equal to - C 5
<: is less than - D 3
>: is greater than - E 1
<=: is less than or equal to - F 2
>=: is greater than or equal to