Lesson 4 Python Maths Score
Lesson 4 Python Maths Score
PROGRAMMING
PYTHON
Learning Outcomes
–Lesson 4
Demonstrate use of variables
to add score to a game
Add responsive score feedback
to the game
Remember this from last lesson?
Maintaining score throughout game
With just a few lines of extra
code you should be able to
maintain the score throughout
the game and give some
feedback at the end.
Open your file saved from last
lesson called maths_questions
Code to add the score
Score = score + 1
Think, pair share
Do you understand what
score = score + 1
means?
Display the score at the end of the game
What code would you have to
type in to display the score at the
end of the game?
Answer
print (score)
Even better if you did this:
print (“Your score was “ +str
(score))
Why do you need to type in
str (score) ?
str (score)
The score variable is an integer
Python cannot add it to the end of
a string.
So the str() function converts it to
a string for the purpose of this line
of code.
Python cannot add strings and
integers together when printing
Responsive feedback solution
score = 0
if score > 2:
print (“Well done!”)
else
print (“Oh dear”)
Responsive feedback solution
Even better if:
“Well done, you scored 3 out of 3 –
very clever”, “Oh dear, you only
scored 1 out of 3 – why not try
again to improve”
Review
–Lesson 4
Demonstrate use of variables
to add score to a game
Add responsive score feedback
to the game
Homework - Questions
Come up with 5 questions you would like to
test in a program
For example – What is the capital of France
Ensure you have the answers too!