Python function program to find the sum of all the numbers in a list

In this python function program, we will find the sum of all the numbers in a list.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function total
  2. Use the def keyword to define the function.
  3. Pass a parameter i.e. list to the function.
  4. Create a variable and assign its value equal to 0.
  5. Use a for loop to iterate over the values in the list.
  6. After each iteration add the values to the variable.
  7. Print the output.
  8. Create a list and pass that list to the function while calling the function.
				
					def total(list1):
    t = 0
    for val in list1:
        t += val
    print("Sum of given list: ",t)
    
l = [6,9,4,5,3]
total(l)
				
			

Output :

				
					Sum of given list:  27
				
			

Related Articles

find the maximum of three numbers.

multiply all the numbers in a list.

Leave a Comment