Year 8 – Intro to Python programming Homework
Lesson 2 – Crunching numbers
Homework
Task 1 .
Read the Python program below:
1 num1 = int(input())
2 num2 = 10 + num1 * 2
3 print(num2)
4 num1 = 20
5 print(num1)
Question 1
When this program is executed, if the user types 10 on the keyboard, what will be
displayed on the screen as a result of executing line 3?
A. 30
B. 40
C. 10 + 10 * 2
D. 10 + num1 * 2
Question 2
When this program is executed, if the user types 10 on the keyboard, what will be
displayed on the screen as a result of executing line 5?
A. 10
B. 20
C. 10 and 20
D. There is an error in the program because a variable cannot hold two values at the
same time
Page 1 Last updated: 16-04-21
Task 2 .
Rearrange the lines in the Python program below, so that you have a runnable program
that holds a meaningful interaction with the user.
1 print("And where do you live", name)
2 print("I’ve never been to", location)
3 name = input()
4 print("What is your name?")
5 location = input()
Write your rearranged program below:
Task 3 .
The incomplete program below is supposed to prompt the user for a distance in miles,
and convert the distance that the user enters to kilometres.
1 print("Enter a distance in miles:")
2 miles = .
3 kilometres = .
4 print(miles, "miles is", kilometres, "km")
Step 1
Complete line 2 so that the value assigned to the miles variable is obtained from what
the user types on the keyboard.
Page 2
Step 2
Complete line 3 so that the program calculates the value of the kilometres variable to
be the equivalent of the miles variable, converted to kilometres. Note that 1 mile is
equal to 1.60934 kilometres.
Resources are updated regularly — the latest version is available at: ncce.io/tcc.
This resource is licensed under the Open Government Licence, version 3. For more information on this
licence, see ncce.io/ogl.
Page 3