0% found this document useful (0 votes)
3 views16 pages

Lesson 5 - Counts - Workbook

This lesson focuses on understanding and using counter variables in Python programming, including how to embed them in IF statements and customize programs with print statements. Students will learn to maintain a score in a quiz game and will be tasked with identifying errors in code, enhancing their programs, and refining their coding skills. The lesson includes practical tasks to apply these concepts, such as adding questions to a quiz and displaying the final score to the user.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views16 pages

Lesson 5 - Counts - Workbook

This lesson focuses on understanding and using counter variables in Python programming, including how to embed them in IF statements and customize programs with print statements. Students will learn to maintain a score in a quiz game and will be tasked with identifying errors in code, enhancing their programs, and refining their coding skills. The lesson includes practical tasks to apply these concepts, such as adding questions to a quiz and displaying the final score to the user.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Lesson 5

Count

Python Programming
Learning & Skills Objectives
 To understand how to use counter variables.

 To understand how to embed counter variables in an IF statement.

 To learn how to customise and refine programs further with print


statements.

 I can introduce a variable that can keep a score (known as a counter).

 I can increment the ‘counter’ variable by 1 in an IF statement.

Keywords
Increment, variable, counter, statement, embed
Lesson Success Criteria
 I know what a counter variable is.
Remembering  I know how to embed a counter variable into an IF
statement.
Understanding
 I can spot errors in code, explain why they are wrong and
I can fix them.
Applying  I can customise a program with print statements.
 I can introduce a variable that can keep a score in my
program.
Analyzing
 I have completed ALL of the tasks in today’s lesson
INDEPENDENTLY.
Evaluating
 I have completed ALL of the extension tasks in today’s
lessons.
Creating  I can refine my program even further and explain how I’ve
done this.
Do now

Can you spot 8 errors!

speed = integer(input("Enter driver's speed: "))


if speed >= 75:
print("Issue speeding fine")
elif speed > 70:
print("Issue warning”)
else:
print("No action”)
To start with ...
print("What is 2 + 2?")
answer = input ()
answer = int(answer)
if answer == 4:
print("Well done")
else:
print("Sorry the answer was 4")

 This is a piece of code that we looked at the start of last lesson.

 Can you remember what this program does? Explain!


 If you were absent last lesson then ask the person next to you to help!
Mini Task One

Open ‘MathsQuiz.py’ from last lesson.

The quiz currently consists of 1 question.


How could we make your Maths Quiz game better?

Your first task today is to add some more


questions to your quiz! You should end up with at
least 5 in total.
You can copy and paste the code to below it if you like.
Remember to test it works though!

Extension – Add extra comments to your code explaining what is happening.


Mini Task One

Paste your code below: Paste the results below:


Adding a counter?

Why is it important to be able to keep a count when


programming something?
To kee
p track
somet of how
c or e hi ng many
To keep a s ( W needs times
m ple) hy i s th t o happe
f or ex a i s n
(in a game import
ant?)

Can you think of any real life scenarios where a


computer keeps a count of something in a program?
e.g. i. A car keeps count of how many miles it’s done.
ii. Fifa2018 on the PS4 keeps count of how
many goals each side’s scored.
Mini Task Two
Introducing the count variable!
 With just a few lines of extra code, it is possible to maintain a score
throughout your Maths Quiz game.

 At the end of the game the player can be given feedback on how well
they’ve done!

score = 0 #this defines variable score, and sets it as zero


print("What is 2 + 2?")
answer = input () (score is a new
answer = int(answer)
variable)
if answer == 4:
print("Well done")
score = score + 1 #this increases score by one
else:
print("Sorry the answer was 4")
Mini Task Two
Introducing the count variable!
1. Update your other questions to include the new
lines of code so that when your players get the
other questions right, the score is increased by 1
each time.

2. Add comments to your code explaining what it is


happening.

Extension – Can you add another counter variable called ‘wrong’ that counts
how many questions the player has got wrong. Think about where this
counter would need to go.
Mini Task Two

Paste your code below: Paste the results below:


Mini Task Three
Showing the results to the player
We would now like to show the score after the user
has attempted answering all of the questions.

1. What variable name is the score stored in?


score

2. What then do we have to type to display this to


the user?
 print(score)

1. How could we make this look a little more


sophisticated?
 print(“Your final score is”, score)
Review!
Learning Objectives Success Criteria
 To understand how to use counter
 I know what a counter variable is.
variables.
 I know how to embed a counter variable into
an IF statement.
 To understand how to embed counter
variables in an IF statement.
 I can spot errors in code, explain why they

 To learn how to customise and refine are wrong and I can fix them.
 I can customise a program with print
programs further with print statements.
statements.  I can introduce a variable that can keep a
score in my program.

 I can introduce a variable that can


 I have completed ALL of the tasks in today’s
keep a score (known as a counter). lesson INDEPENDENTLY.
 I have completed ALL of the extension tasks
 I can increment the ‘counter’ in today’s lessons.
 I can refine my program even further and
variable by 1 in an IF statement.
explain how I’ve done this.
Main Task One
If you can, do all these programs in SCRIPT mode
(i.e. go to FILE, NEW WINDOW…then press F5 to run)
Amend your Maths Quiz program so that it does the following (be sure to
Task:
comment your code):

a) Update the formatting a little bit so that it looks more professional with an
opening title, etc.

b) Asks the user for their name at the beginning of the program and uses their
name when it displays their score at the end.
e.g. Well played Dave, your final score is 1 ... Not good!!

c) The message at the end changes depending upon the player’s score.
e.g. If the player gets lower than 2 they are called a ‘Noob’
Else they are called a ‘MATHS GENIUS’
Main Task One

Paste your code below: Paste the results below:


Review!
Learning Objectives Success Criteria
 To understand how to use counter Level 3
 I know what a counter variable is.
variables.
 I know how to embed a counter variable into
an IF statement.
 To understand how to embed counter
variables in an IF statement. Level 4
 I can spot errors in code, explain why they

 To learn how to customise and refine are wrong and I can fix them.
 I can customise a program with print
programs further with print statements.
statements.  I can introduce a variable that can keep a
score in my program.

Level 5
 I can introduce a variable that can
 I have completed ALL of the tasks in today’s
keep a score (known as a counter). lesson INDEPENDENTLY.
 I have completed ALL of the extension tasks
 I can increment the ‘counter’ in today’s lessons.
 I can refine my program even further and
variable by 1 in an IF statement.
explain how I’ve done this.

You might also like