0
我正在寫一個簡單的程序,我的for循環關閉了一點。它只讀取最後一個條目。我知道這只是輸出最後一項,我知道爲什麼,但我似乎無法修復它。 任何幫助將是偉大的。我可以讓它以另一種方式運行,但我想使用循環。我的程序沒有正確迭代
def main():
testfile = open('tests.txt', 'w')
#### THIS RUNS -- but only output is last entry #####
for count in range(1, 6):
test = int(input('Enter the test score: #' + \
str(count) + ' % '))
testfile.write(str(test) + '\n')
testfile.close()
print('The scores are in the tests.txt file.')
main()
輸出到文本文件中。
>>>
Enter the test score: #1 % 89
Enter the test score: #2 % 98
Enter the test score: #3 % 69
Enter the test score: #4 % 36
Enter the test score: #5 % 36
The scores are in the tests.txt file.
>>>
非常好!謝謝! – user3818550