在python中为测验创建用户定义的循环数

时间:2016-09-21 07:19:43

标签: python python-3.x

我需要在用户定义的时间内提出问题并跟踪尝试

def main(): 
    print("Thank you for taking the Quiz")

    score= 0
    question1 = input("How many donuts are in a dozen? ")
    if question1 == "12":
        print("Correct")
        score = score +1
    else:
        print("Incorrect")

    question2 = input("How many mb are in a gb? ")
    if question2 == "1024":
        print("Correct")
        score = score +1
    else:
        print("Incorrect")

    question3 = input("How many pokemon are in gen 1? ")
    if question3 == "151":
        print("Correct")
        score = score +1
    else:
        print("Incorrect")




    print("The final score is: " + str(score), "out of 3")

main()    

1 个答案:

答案 0 :(得分:0)

我会做这样的事情:

    def main(): 
        print("Thank you for taking the Quiz")

        times = input("How many time you'll play? ")

        for i in range(int(times))
            print("The final score is: " + str(question), "out of 3")

def question():
        score= 0
        question1 = input("How many donuts are in a dozen? ")
        if question1 == "12":
            print("Correct")
            score = score +1
        else:
            print("Incorrect")

        question2 = input("How many mb are in a gb? ")
        if question2 == "1024":
            print("Correct")
            score = score +1
        else:
            print("Incorrect")

        question3 = input("How many pokemon are in gen 1? ")
        if question3 == "151":
            print("Correct")
            score = score +1
        else:
            print("Incorrect")

        return score

    main()