Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.
One possible program:
import random
def ask_addition():
a = random.randint(1, 12)
b = random.randint(1, 12)
ans = int(input(f"What is {a} + {b}? "))
return ans == a + b
def main():
score = 0
for _ in range(3):
if ask_addition():
score += 1
print("Score:", score, "/ 3")
main()