![](/img/trans.png)
[英]TypeError: unsupported operand type(s) for <<: 'str' and 'int'
[英]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])
輸入的x
是str
not int
。 只需在使用前將其轉換為int
:
x= input("Enter rainfall for each of the 12 months:")
x = int(x)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.