我想在一起添加一堆数字,最后的数字是sentinel(999
)。如果输入999
,则输入循环结束并打印答案,否则它将继续循环并添加输入。但是当我运行程序时,它会显示错误:
Traceback (most recent call last):
File "lab9.py", line 4, in <module>
sum += kbInput
TypeError: unsupported operand type(s) for +=: 'builtin_function_or_method' and 'int'
代码如下:
kbInput = input()
while int(kbInput) != 999:
kbInput = input()
sum += kbInput
count += 1
average = sum/average
print("Sum", sum)
print("Average", average)
答案 0 :(得分:2)
Cache::flush()
是内置函数。使用名称sum
并在循环之前将其设置为零:
sum_