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ベースのOS上にいる場合は、単にファイルを 'cat'するだけでよく見えます。 –