Coding basics · 17 of 20
Sum of a list
Return the sum of the numbers in the list, without using sum(). An empty list sums to 0.
What you need
for x in nums visits every item in the list in order. len(nums) is how many items it has, and nums[0] is the first.
nums = [5, 8, 2]
for x in nums:
print(x) # 5, 8, 2
nums[0] # 5Examples
Input nums = [1, 2, 3, 4]
Output 10
Input nums = []
Output 0