【发布时间】:2017-03-11 18:05:10
【问题描述】:
我的程序应该获取每个月的降雨量,并计算一年的总降雨量、平均月降雨量以及降雨量最高(最大)和最低(最小)的月份。
一切都按计划进行,除了最高和最低月份的产出。我需要这个来显示降雨量最高和最低的月份的名称。我可以获得正确的值来显示,而不是月份的名称。
months = ["January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"]
values = []
year = []
for i in months :
values.append(float(input("Enter total rain for " + i + ": ")))
print()
def total():
print("The total rainfall for the year is %.2f" % sum(values))
total()
def average():
print("The average monthly rainfall is %.2f" % float(sum(values)/ 12))
average()
def highest():
print("The highest monthly rainfall is", max(values))
highest()
def lowest():
print("The lowest monthly rainfall is", min(values))
lowest()
【问题讨论】: