Write simple mathematics (combination of addition, subtraction, multiplication) game program for kids which gives ten randomly generated questions. Your program should keep track of the scores for the right answers and should display them to the students after they finished answering all questions. If the answer is right, print Right!. If the answer is wrong print Wrong! and display the right answer. You should write the program code using the loop concept. Also, print the question numbers, when printing the question
from random import randint
scores=0
for _ in range(10):
#generate random number 1
number1 = randint(0,9)
#generate random number 2
number2 = randint(0,9)
#generate randomoperation
operation=randint(0,2)
correctsAnwer=0
#addition
if(operation==0):
print(str(number1)+" + "+str(number2)+" = ?")
correctAnswer=number1+number2
#subtraction
if(operation==1):
print(str(number1)+" - "+str(number2)+" = ?")
correctAnswer=number1-number2
#multiplication
if(operation==2):
print(str(number1)+" * "+str(number2)+" = ?")
correctAnswer=number1*number2
answer=int(input("Your answer: "))
#check answer
if(correctAnswer==answer):
print("Right!")
scores+=1
else:
print(f"Wrong! The right answer is {correctAnswer}")
print("\n")
print(f"Scores is {scores}")
Comments
Leave a comment