对此反驳,我还是不明白

时间:2016-08-27 10:52:07

标签: python-3.5

我之前曾问过我的柜台无法正常工作的原因。所以,在做一个不同的项目时,我意识到我需要一个柜台但却无法找到或放置一个符合我需求的柜台。 (我也很清楚,这可以缩短,但忽略这一点)。柜台只需要提出10个问题,但我无法弄清楚如何适应我所看到的其他问题。

from random import randint
import random
import math


count = 0
print("This game is a quiz to see how good you are at maths. No paper allowed!")

def Start():
    print("No paper allowed nor a calculator!")

    ans1 = input("Do you wish to start? \n")
    if ans1 == "Yes" or ans1 == "yes" or ans1 == "Y" or ans1  == "y":
        Begin(count)
    if ans1 == "no" or ans1 == "No" or ans1 == "n" or ans1 == "N":
        exit()

def Begin(count):

    opers = ['+','-','*',"/"]
    operation = random.choice(opers)
    num1 = random.randint(2,21)
    num2 = random.randint(2,num1)
    num3 = int(eval(str(num1) + operation + str(num2)))


    ans2 = int(input("What is "+str(num1) + operation + str(num2)+"? \n"))
    if ans2 == num3:
        print("Well done! You must be good at maths!")
        Begin(count)

    if ans2 != num3:
        print("You are terrible at maths. Go sit in that corner. (The answer was "+str(num3)+").")
        Begin(count)

def Replay():
    ans3 = input("Would you like to play again? \n")
    if ans3 == "Yes" or ans3 == "yes" or ans3 == "Y" or ans3  == "y":
             Start()
    if ans3 == "no" or ans3 == "No" or ans3 == "n" or ans3 == "N":
             exit()
Start()

1 个答案:

答案 0 :(得分:0)

在Begin函数中添加:

global counter
counter+=1
if counter == 10:
    print("something...")

修改

这有效!

from random import randint
import random
import math

count = 0
print("This game is a quiz to see how good you are at maths. No paper allowed!")


def Start():
    print("No paper allowed nor a calculator!")

    ans1 = input("Do you wish to start? \n")
    if ans1 == "Yes" or ans1 == "yes" or ans1 == "Y" or ans1 == "y":
        Begin()
    if ans1 == "no" or ans1 == "No" or ans1 == "n" or ans1 == "N":
        exit()


def Begin():
    global count
    count+=1
    if count==10:
        print("finished")
        exit()
    opers = ['+', '-', '*', "/"]
    operation = random.choice(opers)
    num1 = random.randint(2
                          , 21)
    num2 = random.randint(2, num1)
    num3 = int(eval(str(num1) + operation + str(num2)))

    ans2 = int(input("What is " + str(num1) + operation + str(num2) + "? \n"))
    if ans2 == num3:
        print("Well done! You must be good at maths!")
        Begin()

    if ans2 != num3:
        print("You are terrible at maths. Go sit in that corner. (The answer was " + str(num3) + ").")
        Begin()


def Replay():
    ans3 = input("Would you like to play again? \n")
    if ans3 == "Yes" or ans3 == "yes" or ans3 == "Y" or ans3 == "y":
        Start()
    if ans3 == "no" or ans3 == "No" or ans3 == "n" or ans3 == "N":
        exit()


Start()