Python:程序不断重复

时间:2016-10-10 12:42:27

标签: python python-3.x

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()

我试图做一个随机数学测验而且我只做了一次问题:

当我运行这个程序时,程序将重复一遍,即使我只调用了一次函数。(我知道这可能是非常基本和混乱但请耐心等待我<3)

0 个答案:

没有答案
相关问题