如何在此文本上固定输入

时间:2019-10-25 14:20:31

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

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

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

1 个答案:

答案 0 :(得分:0)

&希望有帮助!

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