TQC+ 程式語言 Python 3 _ 904 資料計算

請注意:資料夾或程式碼中所提供的檔案路徑,不可進行變動,read.txt檔案需為UTF-8編碼格式。

說明:
請撰寫一程式,讀取read.txt(每一列的格式為名字和身高、體重,以空白分隔)並顯示檔案內容、所有人的平均身高、平均體重以及最高者、最重者。
提示:輸出浮點數到小數點後第二位。
檔案連結:read.txt (請另存檔案,必須與程式同一資料夾)
範例輸出:
Ben 175 65

Cathy 155 55

Tony 172 75
Average height: 167.33
Average weight: 65.00
The tallest is Ben with 175.00cm
The heaviest is Tony with 75.00kg
程式碼:
nameLi = []
heightLi = []
weightLi = []

with open('read.txt','r',encoding='utf-8') as fp
    for line in fp:
        print(line)
        temp = line.replace('\n','').split(' ')
        nameLi.append( temp[0] )
        heightLi.append( temp[1] )
        weightLi.append( temp[2] )

print( nameLi )
print( heightLi )
print( weightLi )

沒有留言:

張貼留言