千葉市の気温と降水量の平年値(1981-2010)が次のように与えられている。
最小値,平均値,最大値を求めるプログラムを作成しなさい。
temp = [5.7, 6.1, 8.9, 14.0, 18.3, 21.3, 25.0, 26.7, 23.3, 18.0, 12.9, 8.3] n = len(temp) temp_min = temp[0] temp_max = temp[0] s = temp[0] i = 1 while i < n: if temp_max < temp[i]: temp_max = temp[i] if temp_min > temp[i]: temp_min = temp[i] s = s + temp[i] i = i + 1 print("min: ", temp_min) print("mean:", int(s / n * 10 + 0.5)/10) print("max: ", temp_max)
H:\prg1\06>python minmaxmean.py↵
min: 5.7
mean: 15.7
max: 26.7