1.

Write a function to give the sum of all the numbers in list?Sample list − (100, 200, 300, 400, 0, 500)Expected output − 1500

Answer»

Program for sum of all the numbers in list is −

def sum(numbers):   total = 0   for num in numbers:      total+=num   print(''Sum of the numbers: '', total)sum((100, 200, 300, 400, 0, 500))

We define a function ‘sum’ with numbers as parameter. The in for loop we store the sum of all the values of list.



Discussion

No Comment Found