因此,我收到此错误:追溯(最近一次通话最近):文件“ C:/ Users /”,第8行,在
    总数=总数+ x
TypeError:+不支持的操作数类型:“ int”和“ str”

array = []
total = 0
max = 0
min = 0
for i in range(12):
    x= input("Enter rainfall for each of the 12 months:")
array.append(x)
total = total+x
if array[max]< x:
    max = i
if array[min] > x:
    min = i
print("The total rainfall in the year is ", total)
print("The average rainfall for the year is ", total / 12.0)
print("Month number ", max + 1, " has the highest rainfall which is ", array[max])
print("Month number ", min + 1, " has the lowest rainfall which is ", array[min])

最佳答案

输入的x不是str。只需将其转换为int即可使用:

x= input("Enter rainfall for each of the 12 months:")
x = int(x)

07-24 09:39
查看更多