I'm trying to write a small python program that asks random math question, but i'm stuck. The random questions being asked aren't accepting the answers even if the answer is correct. Plus it keeps repeating the question. Could you please review my code and let me know what i'm missing?
import random
import operator
import time
name = input("Type your name: ") #user name is stored inside name variable
print ("Hi",name,"This math quiz will test your basic math ability.") #Quick
intro
print ("Please press 'Enter' after every input")
print (" ")
time.sleep(1)
operators = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.truediv
}
randNum1 = random.randint(9, 999)
randNum2 = random.randint(9, 999)
ops = random.choice(list(operators.keys()))
question = 0
star = 0
def ask_Question():
que = randNum1, ops, randNum2
print ("What is", randNum1, ops, randNum2)
que_ans = int(input(">>>"))
if que == que_ans:
print ("Congrats! You earned your first star.")
print (" ")
elif que != que_ans:
print ("Error! Better luck next time.")
def main():
while question <= 4:
ask_Question()
main()
Aucun commentaire:
Enregistrer un commentaire