Lesson 7: Multiplication test (Variables, Control-flow, Loops)

posted Dec 12, 2018, 8:03 AM by Attila Lengyel
import random

print("How many questions?")
q = int(input())
score = 0

for i in range(0,q):
a = random.randint(2,12)
b = random.randint(2,12)
print("What is", a, "x", b, "?")
c = int(input())
if a * b == c:
print("o - Correct. It is", c)
score = score + 1
else:
print("x - Incorrect. It is", a * b)

print("You scored", score, "points")
print("Percentage: ", (score / q) * 100,"%")

Comments