0
我爲我的學生創建了跟蹤測試的代碼,代碼有效,但格式設置已關閉。而不是甚至列它們顯示不正確。我的代碼是:Python,列寬問題
def main():
mytests = open('test.txt','r')
count = 0
total = 0
print('Reading six tests and scores')
print()
print('TEST SCORE')
for line in mytests:
name = line.rstrip('\n')
score = int(mytests.readline())
print(name,' ', score)
count += 1
total += score
mytests.close()
print('Average: ',format(total/count,'.1f'))
main()
輸出看起來像: 讀6次測試,成績
TEST SCORE
History 98
Math 89
Geology 78
Space 78
PE 90
Religion 75
Average: 84.7
Does anybody have any ideas on how I can format the score column to be in alignment?
上述現有問題可能會解決您的問題,但如果我遇到了這個問題,我會將數據寫入.csv,默認情況下這些數據是由製表符分隔的。如果你使用的是基於UNIX的操作系統,那麼你可以簡單地使用這個文件,並且它會看起來很好,我相信。 –