Editor

Sum of List

#11 · Lists · Beginner · 40 XP · about 4 min

Write a function called sum_list(numbers) that returns the sum of all numbers in a list.

Challenge: Try to solve this without using Python's built-in sum() function!

Example

sum_list([1, 2, 3, 4, 5])  # Returns 15
sum_list([10, -5, 3])      # Returns 8
sum_list([])               # Returns 0

Requirements

  • Return the sum of all numbers
  • Handle empty lists (return 0)
  • Handle negative numbers

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.