寻找编码项目的建议

2024-05-21 05:19:46 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,到目前为止,如果给出的答案过高或过低,代码需要重新询问给出的问题。此外,如果答案是正确的,它应该告诉他们,然后回到问题(“你想要多少问题?”)

def main():

    gamenumber = int(input("How many problems do you want?\n"))
    count = 0
    while count < gamenumber:
        num_1 = randint(1,10)
        num_2 = randint(1,10)
        guess = int(input("What is " + str(num_1) + "x" + str(num_2) + "."))
        answer = (num_1*num_2)
        count += 1

        for guess in range(1):
            if guess == answer:
                print (' Thats Correct!')
        for guess in range(1):
            if guess > answer:
                print (' Answer is to high')
        for guess in range(1):
            if guess < answer:
                print ('Answer is to low')
main()

Tags: 答案answerinforinputifismain
2条回答

首先你能检查一下你的密码吗。在for循环中使用了“guess”变量。执行程序时,guess的值为40(4X10)。执行for语句时,猜测值变为0,因为您得到的输出是低的。确保将for循环中使用的变量更改为“num”,然后检查输出

为什么要用3个for循环呢?你可以用一个for循环

请在下面找到code:- 你知道吗

from random import randint
def main():

    ans = 'y'
    while ans != 'n':
        gamenumber = int(input("How many problems do you want?\n"))
        count = 0
        while count < gamenumber:
            num_1 = randint(1,10)
            num_2 = randint(1,10)
            guess = int(input("What is " + str(num_1) + "x" + str(num_2) + "."))
            print(guess)
            answer = (num_1*num_2)
            print("=====>",answer)
            count += 1

            for num in range(1):
                if guess == answer:
                    print (' Thats Correct!')
                elif guess > answer:
                    print (' Answer is to high')
                elif guess < answer:
                    print ('Answer is to low')
        yes_no_input = str(input("Do you want to continue (y/n) ?"))
        ans = accept_ans(yes_no_input)
        if ans == 'n':
            print("thanks for the test")
            break;

def accept_ans(ans):

    if not ans.isalpha():
        print("Enter only y and n")
        ans = str(input("Do you want to continue (y/n) ?"))

    if ans == 'y' or ans == 'n':
        return ans

    if ans != 'y' or ans != 'n':
        print("please enter y for YES and n for NO")
        ans = str(input("Do you want to continue (y/n) ?"))
        if ans != 'y' or ans != 'n':
            accept_ans(ans)

if __name__ == '__main__':
    main()

之后

print("Thats correct")

你得打电话给警察

main()

再次运行

相关问题 更多 >