Year 9TechnologySupport
Each program is written in Python, one line at a time. Read it carefully and trace it line by line before you answer. Write the exact output where a question asks what the program prints. When you write code, put each instruction on its own line.
AVariables and data types
- 1.
What does a variable do in a program?
(1 mark)- It stores a value under a name so the program can use or change it later
- It prints a message on the screen
- It repeats a block of code
- It stops the program when there is an error
- 2.
Match each value to its Python data type.
(4 marks)- 17
- 4.5
- "hello"
- True
- Ainteger (int), a whole number
- Bstring (str), text inside quotation marks
- Cfloat, a number with a decimal point
- DBoolean (bool), either True or False
- 3.
Worked example: score = 4, then score = score + 1. The new value of score is 5, because Python works out the right side first and then stores it. Now trace this program. What is the value of lives at the end? lives = 3 lives = lives - 1 lives = lives + 5
(1 mark) - 4.
In Python, a single equals sign (=) checks whether two values are the same.
(1 mark)- True
- False
BDecisions and loops
- 5.
What does this program print? temp = 22 if temp > 20: print("Wear a t-shirt") else: print("Bring a jumper")
(1 mark)- Wear a t-shirt
- Bring a jumper
- Wear a t-shirt and Bring a jumper
- Nothing
- 6.
Hint: range(5) counts 0, 1, 2, 3, 4. This loop runs times, so it prints Hip hip hooray that many times. for i in range(5): print("Hip hip hooray")
(1 mark) - 7.
Hint: range stops just before the second number. Which numbers does range(1, 4) give?
(1 mark)- 1, 2, 3
- 1, 2, 3, 4
- 0, 1, 2, 3
- 1 and 4 only
- 8.
This line has a bug, so Python shows an error. print("Hello) Sentence starter: The bug is ... The fixed line is ...
(2 marks)