Total List Sum

Adding up a list is one of the most common operations in programs, such as calculating a total price, score, or quantity. Write a function sum_list that returns the sum of all numbers in nums. If the list is empty, the sum should be 0. Negative numbers are added using the usual rules.

Примеры

Ввод
[1, 2, 3, 4]
Вывод
10
Ввод
[]
Вывод
0
Ввод
[-5, 5]
Вывод
0

Нужно реализовать

def sum_list(nums: list[int]) -> int:

Теги

listsmath
PostgreSQLv16

Tukaj bo rezultat izvajanja kode

Visible tests
1
Input
[1,2,3,4]
Expected10
2
Input
[]
Expected0
3
Input
[-5,5]
Expected0
4
Input
[100]
Expected100
5
Input
[1,-2,3,-4,5]
Expected3
6
Input
[-4,6]
Expected2
Focus radio
Paused · SomaFM · Fluid