0% found this document useful (0 votes)
32 views

Year 9-Lesson 5-Intro To Python Programming-1

Uploaded by

aaroush199
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Year 9-Lesson 5-Intro To Python Programming-1

Uploaded by

aaroush199
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Year 9 Unit 1

Intro to Python programming


ICT
Lesson 5
Round and round
Starter activity
Making predictions
Question .
What will this program display when it is
count = 3 executed?
print(count)
A.
1 There is no valid value for count.
count = count-1
This will result in an error.
print(count) B.
2 It will print 2.
C.
3 It will print 3.
▹ D.
4 It will print 3 and then 2.
Starter activity
Making predictions
Assignments are not equations.
Assignments are instructions to be executed.
count = 3
print(count)
This is an instruction to:
count = count-1
evaluate the expression count-1 and
print(count)
assign the value back to count
(replacing the previous value).
?
This is an instruction to:
decrease the value of count by 1.
Starter activity
Making predictions: answer
Question .
What will this program display when it is
count = 3
executed?
print(count) State . Output .
count = count-1 2
count 3 3
print(count)
count 2 2
Outcomes
In this lesson, you will...
● Use iteration (while statements) to allow the flow of program execution to
include loops
● Use variables as counters
Activity 1
Count
count = 3 Question .
print(count) What will this extended program
count = count-1 display when it is executed?
print(count)
The previous program
ended here.
Use your worksheet to answer.
count = count-1 Then, move on to the next tasks.
print(count)
count = count-1
Activity 1
Count: walk-through
count = 3 Question .
print(count) What will this extended program display
count = count-1 when it is executed?
print(count) State . Output .
count = count-1 count 3 3
print(count) count 2 2
count = count-1
count 1 1

count 0
Activity 1
Count: iterative

count = 3
print(count) count = 3
count = count-1 while count >= 1:
print(count) print(count)
count = count-1 count = count-1
print(count)
count = count-1
Activity 1
Count: solutions

count = 3 count = 10 count = 1


while count >= 1: while count >= 1: while count <= 20:
print(count) print(count) print(count)
count = count-1 count = count-1 count = count+3
print("Lift off!")
Activity 2
Times tables practice

Use pair programming .


Driver
Control the keyboard and mouse.
Navigator
Provide support and instructions.
Alternate between roles.
Activity 2
Times tables practice: a single question

from random import randint


a = randint(2,12) Generate two random integers a and b .
b = randint(2,12)
print(a, "times", b, "=") Ask the user for the product of a and b .
answer = int(input())
product = a * b Calculate the correct answer .
if answer == product: Check the user’s answer and provide
print("That is correct") feedback .
else:
print("I am sorry")
print(a, "times", b, "is", product)
Activity 2
Times tables practice: multiple questions

Start from your current program.


Complete the tasks in your worksheet to
build a more complete times tables
practice game.
Activity 3
Some code reading
from random import randint from random import randint
rolls = 0 rolls = 0
sixes = 0 sixes = 0
while rolls < 10: while sixes < 10:
dice = randint(1,6) dice = randint(1,6)
if dice == 6: if dice == 6:
sixes = sixes + 1 sixes = sixes + 1
rolls = rolls + 1 rolls = rolls + 1

The only difference between these two programs is the condition in


the while loop. When does each loop terminate?
Summary
In this lesson, you... Next lesson, you will...
Used iteration (while Apply what you’ve learnt and
statements) to allow the flow of use iteration even more!
program execution to include
loops Take a quiz, to assess what you’ve learnt

Used variables as counters

You might also like