我有以下代码,它将询问用户每个月的降雨量,并将其附加到rainfall_inch列表中,并计算average 但我有两个问题
1) 在用户输入一个数字和下一个输入运行后,上一个输入显示在下一个输入后面。
"Enter rainfallJanuary : 3
Enter rainfallFebruary 3 : 4"
等等
2)问题是list我的代码“' '对象不能解释为整数”。
def main():
rainfall_inch = []
name_month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
for item in name_month:
x = input()
print("Enter rainfall" + item, x, ": ", end=' ')
rainfall_inch.append(x)
b = [float(x) for x in range(rainfall_inch)]
print(b)
print("average rainfall is:", computeAverage(b))
def computeAverage(values):
#find average of rainfull
total = 0.0
for x in values:
total+=x
average = total/len(values)
return average
main()
帮助谢谢
繁星coding
交互式爱情
相关分类