Sum of Elements in a List
Sum of Elements in a List
Tags: Data Structures Basics
Credit: CodingChallenge
Difficulty: Beginner
Type: Text
Category: Practice
Time Allowed: 5 s
Description:
Write a function that takes a list of numbers and returns the sum of all the elements. This problem is designed to help you practice working with lists and basic iteration
. The function should accept one parameter and return the sum of the elements.
Constraints:
- The input will be a
list
of numbers (integers or floats). - The list can be empty, in which case the sum is
0
. - The function should
return
anumber
representing the sum of the elements.
Example:
- Input:
[1, 2, 3, 4, 5]
- Output:
15
Test Case | Input | Expected Output |
---|---|---|
1 | [] | 0 |
2 | [1, 2, 3, 4, 5] | 15 |
3 | [-1, -2, -3] | -6 |
4 | [0, 0, 0] | 0 |
5 | [100] | 100 |
6 | [1.5, 2.5, 3.5] | 7.5 |
7 | [-1.5, 2.5, -3.5] | -2.5 |
Leave a Comment
Please login to leave a comment.