Lesson 6:
Putting it all
together
Year 8 – Intro to Python programming
Starter activity
Guess my lucky number: multiple attempts
lucky = 13 1. Pick a lucky number .
print("Can you guess my lucky number?") 2. Ask the user to guess .
guess = int(input())
if guess == lucky: 3. Display feedback to the user .
print("Amazing, you guessed it")
else:
print("Sorry, it’s not", guess)
print("Nice playing with you") 4. Say goodbye .
Which of these program segments will need to be
repeated if the user is allowed multiple guesses?
Starter activity
Guess my lucky number: multiple attempts
lucky = 13 Pick a lucky number
↺
print("Can you guess my lucky number?") Ask the user to guess .
guess = int(input())
if guess == lucky: Display feedback to the user .
print("Amazing, you guessed it")
else:
print("Sorry, it’s not", guess)
print("Nice playing with you") Say goodbye
Which of these program segments will need to be
repeated if the user is allowed multiple guesses?
Objectives
In this lesson, you will...
● Use three control structures (sequence, selection, and iteration)
to build a more complex program
● Use Boolean variables, operators, and expressions
● Take a quiz, to assess what you have learnt
Activity 1
Lucky number revisited
Use pair programming .
Driver
Control the keyboard and mouse.
Navigator
Provide support and instructions.
Alternate between roles.
Activity 1
Guess my lucky number: multiple attempts
lucky = 13 Pick a lucky number
↺
print("Can you guess my lucky number?") Ask the user to guess .
guess = int(input())
if guess == lucky: Display feedback to the user .
print("Amazing, you guessed it")
else:
print("Sorry, it’s not", guess)
print("Nice playing with you") Say goodbye
Live coding (ncce.io/py-lucky-6)
Activity 1
Guess my lucky number: run your program
lucky = 13 Faced with an error? Here are some
things that you will need to check:
guessed = False
while guessed == False: ◻ Is the F in False capitalised?
↺ ◻ Does the condition use == to
print("Can you guess my lucky number?")
check if the value of guessed is
guess = int(input())
False?
if guess == lucky: ◻ Have you remembered the colon
print("Amazing, you guessed it") : after the condition in while?
else:
◻ Have you used indentation, to
print("Sorry, it’s not", guess)
indicate which statements
print("Nice playing with you") belong to the while block?
Tip: Press the ‘Stop’ button or try
Control+C to terminate your
program.
Activity 2
Lucky number revisited
Start from your current program.
Complete the tasks in your worksheet to
build a more complete ‘Guess the number’
game.
Activity 2
Logical operators in Python
You can use these operators to Examples
combine logical expressions.
not negation not a == 1
and conjunction b > 10 and c <= d
or disjunction e == 10 or f != 1
Expressions formed using these operators
evaluate to either True or False.
Assessment
Summative assessment
You will now take a quiz, to
assess your learning
throughout this unit.
Good luck!
1
0
Assessment
Summative assessment: feedback
1
1
Summary
Unit takeaways
On a sticky note, write:
One thing that impressed you
One thing that you learnt
(and that you’ll remember)
And one thing that you didn’t
really enjoy
Summary
In this lesson, you...
Used three control structures
(sequence, selection, and
iteration) to build a more
complex program
Used Boolean variables,
operators, and expressions
Took a quiz, to assess what you
have learnt
Summary
In this unit, you...
Explored what basic
programming structures look like
in Python
Built your first Python programs