The following program runs a math quiz consisting of 10 multiplication problems
ID: 663557 • Letter: T
Question
The following program runs a math quiz consisting of 10 multiplication problems involving operands between 1 and 10:
import random
correct = 0
for i in range(10):
num1 = random.randint(1, 10)
num2 = random.randint(1, 10)
prod = num1 * num2
ans = int(raw_input("What is " + str(num1) + " times " + str(num2) + "? "))
if ans == prod:
print "That's right -- well done. "
correct += 1
else:
print "No, I'm afraid the answer is ", prod, " "
print " I asked you 10 questions. You got ", correct, " of them right."
print "Well done!"
Please help me do the following:
Modify the program so that the user can choose how many questions they will be asked. Don’t allow them to choose 0 or a negative number.
Add levels to the program:
o Beginner - with operands between 1 and 10
o Intermediate - with operands between 1 and 25
o Advanced - with operands between 1 and 50
o The user should choose the level when starting a quiz.
Modify the message at the end so that it says:
o Well done! if the user answered more than 3/4 of the questions correctly.
o You need more practice if they get between 1/2 and 3/4 of the questions correct.
o Please ask your math teacher for help! if they get less than 1/2 of the questions correct.
(Round up if in doubt – the user needs to answer 5 questions to get ¾ of 6 correct)
Allow the user to start another quiz without restarting the program.
Let the user choose the question type: addition, subtraction, multiplication, or mixed (randomly choose for each question).
This is in Python, using IDLE. If possible, please help me come up with a short, clean, and elegant solution.
Explanation / Answer
response = raw_input("how many questions you want to answer ")
if response <=0:
print "Error: Please enter a positive number and which is greater than zero"
break
elif(response <=10):
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.