Year 8TechnologySupport
Read each program line by line, as the computer would. Indented lines (4 spaces) belong to the if, elif or else line above them. Write your code answers carefully, with the right spaces and colons.
ARead the code
Work out what each program prints.
- 1.
Match each piece of Python to what it does.
2 marks- print()
- input()
- int()
- if
- Aturns text into a whole number
- Bwaits for the user to type something
- Cruns code only when a condition is true
- Dshows something on the screen
- 2.
What does this program print? name = "Aroha" print("Hi " + name)
1 mark- Hi Aroha
- Hi name
- "Hi " + name
- Nothing, it has an error
- 3.
Worked example: x = 3, then x = x + 2, so x is now 5. What does this program print? lives = 3 lives = lives - 1 print(lives)
1 mark - 4.
What does this program print? score = 7 if score > 5: print("Well done") else: print("Keep practising")
1 mark- Well done
- Keep practising
- Well done Keep practising
- 7
BFind the bug
Each program has one mistake.
- 5.
In Python, a single = sign checks whether two things are equal.
1 mark- True
- False
- 6.
This program has an error. Hint: look at the end of the first line. if age > 12 print("Teenager")
1 mark - 7.
Write one line of Python that stores the number 30 in a variable called minutes.
1 mark