In: Computer Science
Use Python 3, please type.
Write a Python 3 program which is an arithmetic quiz for children. The program asks the user to calculate the multiplication of two numbers generated at random in your code. The numbers should be in the range 1 through 10. User input is shown in bold black font in the example below.
You will need to use random numbers. You should type the recommended comments at the top of your code and include three test runs in the comments.
Example program run:
Please enter the result of multiplying 6 x 7 :
42
Correct.
Another question? (y/n):
y
Please enter the result of multiplying 2 x 7 :
13
Incorrect.
Another question? (y/n):
n
You scored 1 out of 2. That is 50% and letter grade": P
import random correct = 0 total = 0 while True: n1 = random.randint(1, 10) n2 = random.randint(1, 10) answer = int(input("Please enter the result of multiplying {} x {} :\n".format(n1, n2))) if answer == n1 * n2: print("Correct.") correct += 1 else: print("Incorrect.") total += 1 choice = input("Another question? (y/n):\n") if choice == 'n': break grade = (correct * 100) / total if grade >= 90: letter_grade = 'A' elif grade >= 80: letter_grade = 'B' elif grade >= 70: letter_grade = 'C' elif grade >= 60: letter_grade = 'D' else: letter_grade = 'F' print("You scored {} out of {}. That is {}% and letter grade: {}".format(correct, total, grade, letter_grade))