Program to calculate the sum of numbers from 0 to 10

In this python function program, we will calculate the sum of numbers from 0 to 10.

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. Create a variable and assign its value equal to 0.
  4. Use a for loop with the range function to iterate over numbers from 1-10.
  5. After each iteration add the numbers to the variable.
  6. Print the sum of numbers between 1-10.
  7. Call the function to get the output.
				
					def total():
    t = 0
    for i in range(1,11):
        t += i
    print("Total: ",t)
    
total()
				
			

Output :

				
					Total:  55
				
			

Related Articles

find the LCM of two numbers.

find the HCF of two numbers.

Leave a Comment