import random
print("Welcome To Arthur's Quiz,\nfeel free to revise the answers once you have completed.\n")
redos=0
def multiplyquestion():
first_num=random.randint(1,100)
second_num=random.randint(1,100)
real_answer= first_num*second_num
human_answer=0
while real_answer!=human_answer:
human_answer = float(input("What is "+str(first_num)+" x "+str(second_num)+" : "))
if real_answer==human_answer:
print("Well done!, The answer was: "+str(real_answer)+"\n")
else:
print("Incorrect answer, Please Try Again.\n")
global redos
redos = redos+1
def divisionquestion():
first_num=random.randint(1,100)
second_num=random.randint(1,100)
real_answer= first_num/second_num
human_answer=0
while real_answer!=human_answer:
human_answer = float(input("What is "+str(first_num)+" / "+str(second_num)+" : "))
if real_answer==human_answer:
print("Well done!, The answer was: "+str(real_answer)+"\n")
else:
print("Inccorrect answer, Please Try Again.\n")
global redos
redos = redos+1
def additionquestion():
first_num=random.randint(1,100)
second_num=random.randint(1,100)
real_answer= first_num+second_num
human_answer=0
while real_answer!=human_answer:
human_answer = float(input("What is "+str(first_num)+" + "+str(second_num)+" : "))
if real_answer==human_answer:
print("Well done!, The answer was: "+str(real_answer)+"\n")
else:
print("Inccorrect answer, Please Try Again.\n")
global redos
redos = redos+1
def subtractquestion():
first_num=random.randint(1,100)
second_num=random.randint(1,100)
real_answer= first_num-second_num
human_answer=0
while real_answer!=human_answer:
human_answer = float(input("What is "+str(first_num)+" - "+str(second_num)+" : "))
if real_answer==human_answer:
print("Well done!, The answer was: "+str(real_answer)+"\n")
else:
print("Inccorrect answer, Please Try Again.\n")
global redos
redos = redos+1
def main():
for i in range(0,1):
question_code=random.randint(1,4)
if question_code == 1:
subtractquestion()
elif question_code ==2:
additionquestion()
elif question_code == 3:
divisionquestion()
elif question_code==4:
multiplyquestion()
# Main program starts here
main()
I'm trying to do a randomised math quiz and I have made it only do one question for times sake:
When I run this the program will repeat itself over an over again, even though I have only called upon a function once.(I understand this is probably very basic and messy but please have patience with me <3)