【问题标题】:How to fix the input on this text如何修复此文本的输入
【发布时间】:2019-10-25 14:20:31
【问题描述】:
digit= open('pi.txt','r')
guess = digit.readline()
while guess.isdigit():
    if digit == ".":
        digit = pi.read(1)
    elif digit == "\n":
        seed += 1
        pi.seek(seed)
        digit = pi.read(1)
    else:
        if int(guess) == int(digit):
            print(guess, "is correct")
            correct += 1
        else:
            print("Sorry, number is", digit, "not", guess)
            wrong += 1
    guess = input("enter another digit guess or \"q\": ")
    digit = pi.read(1)


print("\nThanks for playing\nNumber Correct:", correct, "\nNumber Incorrect:", wrong)
pi.close()

输出:

Thanks for playing
Number Correct: 0 
Number Incorrect: 0

需要弄清楚如何为正确和错误的数字添加数字,我不知道该怎么做。

【问题讨论】:

  • 欢迎来到 StackOverflow !我看到的一个问题是您的代码中没有定义correctwrong。你需要在while循环之前添加correct = 0wrong = 0

标签: python-3.x curl input printing pi


【解决方案1】:

&希望对您有所帮助!

  1. 维护两个列表correct_responsesincorrect_responses
correct_responses = []
incorrect_responses = []

while guess.isdigit():
    if digit == ".":
        digit = pi.read(1)
    elif digit == "\n":
        seed += 1
        pi.seek(seed)
        digit = pi.read(1)
    else:
        if int(guess) == int(digit):
            print(guess, "is correct")
            correct += 1
            correct_responses.append()
        else:
            print("Sorry, number is", digit, "not", guess)
            wrong += 1
    guess = input("enter another digit guess or \"q\": ")
    digit = pi.read(1)


print("\nThanks for playing\nNumber Correct:", correct, "\nNumber Incorrect:", wrong)
pi.close()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多