TQC+ 程式語言 Python 3 _ 807 字串加總

說明:
請撰寫一程式,要求使用者輸入一字串,該字串為五個數字,以空白隔開。請將此五個數字加總(Total)並計算平均(Average)。
範例輸入:
-2 34 18 29 -56
範例輸出:
Total = 23
Average = 4.6
程式碼:
numStr, total = input(), 0
numLi = numStr.split(' ')

for i in numLi: total += int(i)

print ('Total =', total)
print ('Average =', total / len( numLi ))

沒有留言:

張貼留言