私はを解決しようとするが、私はこのコードでTypeError
を取得するPythonの行使10.3Pythonの:TypeError例外:「int型のオブジェクトが反復可能ではありません(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]
.
考える:
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 –