我试图解决认为Python演习10.3的Python:类型错误: '诠释' 对象不是可迭代(认为Python 10.3)
Write a function that takes a list of numbers and returns the cumulative sum; that is, a new list where the ith element is the sum of the first
i + 1
elements from the original list. For example, the cumulative sum of[1, 2, 3]
is[1, 3, 6]
.
我得到一个TypeError
与此代码:
def culm_sum(num):
res= []
a = 0
for i in num:
a += i
res += a
return res
当我打电话culm_sum([1, 2, 3])
我得到
TypeError: 'int' object is not iterable
谢谢!
退房此线程,它有不止一个答案您的问题 http://stackoverflow.com/questions/494594/how-to-write-the-fibonacci-sequence-in-python –