Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
145 views

9.05 Python Scheme of Work

This document provides instructions for creating a math quiz program with Python. It describes how to: 1) Add multiple questions by copying and pasting the code for the sample one question quiz. 2) Track the score throughout the quiz by initializing a score variable and incrementing it for correct answers. 3) Display the current score after each question by printing the score variable. 4) Personalize the score message by getting the user's name and including it when printing the score.

Uploaded by

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

9.05 Python Scheme of Work

This document provides instructions for creating a math quiz program with Python. It describes how to: 1) Add multiple questions by copying and pasting the code for the sample one question quiz. 2) Track the score throughout the quiz by initializing a score variable and incrementing it for correct answers. 3) Display the current score after each question by printing the score variable. 4) Personalize the score message by getting the user's name and including it when printing the score.

Uploaded by

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

COMPUTER PROGRAMMING

Year 9 – Unit 9.04


Last week, you entered in this program called MathsQuiz.py

print("What is 2 + 2?")
answer = input ()
answer = int(answer)
if answer == 4:
print("Well done")
else:
print("Sorry the answer was 4")

It would be good to have 5 questions, rather than just 1. Copy the


code in your program and paste it below for each new question…
see next slide for example.
Question 1

Question 2

Question 3
With just a few lines of extra code, it should be possible to
maintain a score throughout a game and then give the user some
feedback at the end.

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)
if answer == 4: variable)
print("Well done")
score = score + 1 #this increases score by one
else:
print("Sorry the answer was 4")

Add the two highlighted lines of code to your FIRST question only
For the remaining 4 questions, just add the line
score = score + 1 #this increases score by one
…as shown below

print("What is 13 + 80?")
answer = input ()
answer = int(answer)
if answer == 93:
print("Well done")
score = score + 1 #this increases score by one
else:
print("Sorry the answer was 93")
We would also like to show the score after the user has attempted
answering the question. Remember, the score is stored in a
variable called score and is simply print(score)

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


print("What is 2 + 2?")
answer = input ()
answer = int(answer)
if answer == 4:
print("Well done")
score = score + 1 #this increases score by one
else:
print("Sorry the answer was 4")
print(score)
A more sophisticated way of presenting the score could be…

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


print("What is 2 + 2?")
answer = input ()
answer = int(answer)
if answer == 4:
print("Well done")
score = score + 1 #this increases score by one
else:
print("Sorry the answer was 4")
print(“Your current score is: “ , score)
If you can, do all these programs in SCRIPT mode
(i.e. go to FILE, NEW WINDOW…then press F5 to run)
Task:Amend your Maths Quiz program so that it prompts the end
user for their name at the beginning of the program.

When the score is displayed, it should show the message…

[name_variable], your score is [score_variable]

This should be displayed after each attempt at a question.

Example
Tim, your score is 1

Save your Maths Quiz


game.

You might also like