L2 Slides - Intro to Python programming - Y8
L2 Slides - Intro to Python programming - Y8
Crunching
numbers
Year 8 – Intro to Python programming
Starter activity
lucky = 13 Question .
print("My lucky number is", lucky) What will be the output of print when this
program is executed?
A.
1 My lucky number is lucky
▹ B. My lucky number is 13
2
3
C. It is not possible to know the output
without executing the program
D. There is an error in the program
4
A.
1 My lucky number is lucky
B. My lucky number is 13
2
3
C. It is not possible to know the output
without executing the program
▹ D. There is an error in the program
4
A.
1 Hello user
▹ B. Hello and whatever the user has typed
2
on the keyboard
C. It is not possible to know the output
3
Assignments
Referring to variables
The machine
executes the code
State .
days 365
Output .
Activity 1
The machine
executes the code
State .
days 365
quad 1461
Output .
Activity 1
The machine
executes the code
State .
days 365
quad 1461
Output .
1461 days in four years
Activity 1
Order matters
Subtle points
number = 5 Question .
double = 2 * number What will be the value of double, after
A number = 15 executing lineA ?
A.
▹ 1 10
B. 30
2
Why .
Line A only affects the number variable.
The value of double is not ‘updated’.
Activity 2
Subtle points
number = 5 Question .
A number = number + 10 What will be the value of number, after
executing lineA ?
A.
1 5 and 15
▹ B. 15
2
Why .
The expression number + 10 is evaluated
and the result is assigned to number.
The previous value of number is replaced.
Activity 3
Driver
Control the keyboard and mouse.
Navigator
Provide support and instructions.
Live coding
age 12
Activity 4
print("Weight on Earth?")
weight_earth = int(input())
weight_moon = weight_earth / 6
print("Weight on moon:", weight_moon)
Activity 4