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
需要弄清楚如何为正确和不正确的数字添加数字,我不知道该怎么办。
答案 0 :(得分:0)
&希望有帮助!
correct_responses
和incorrect_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()