繁体   English   中英

Python Rainfall程序TypeError:+不支持的操作数类型:'int'和'str'

[英]Python Rainfall program TypeError: unsupported operand type(s) for +: 'int' and 'str'

所以我遇到了这个错误:追溯(最近一次调用是最近一次):文件“ C:/ Users /”,第8行,总计= total + 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])

输入的xstr not int 只需在使用前将其转换为int

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM