5人の点数を読み込んで合計点と平均点を表示
明解C言語 入門編 > 5. 配列 >
5人の点数を読み込んで合計点と平均点を表示
Python
# coding: Shift_JIS print "点数を入力してください。" score1 = int(raw_input("1番:")) score2 = int(raw_input("2番:")) score3 = int(raw_input("3番:")) score4 = int(raw_input("4番:")) score5 = int(raw_input("5番:")) sum = 0 sum += score1 sum += score2 sum += score3 sum += score4 sum += score5 print "合計点%d" % sum print "平均点%f" % (float(sum) / 5)
実行結果
N:\>python lesson_05_029.py
点数を入力してください。
1番:95
2番:83
3番:85
4番:63
5番:89
合計点415
平均点83.000000