Answer to Question #178330 in Python for tas

Question #178330

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


1
Expert's answer
2021-04-07T22:58:30-0400
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}")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS