簡體   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