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
- Create a function total
- Use the def keyword to define the function.
- Create a variable and assign its value equal to 0.
- Use a for loop with the range function to iterate over numbers from 1-10.
- After each iteration add the numbers to the variable.
- Print the sum of numbers between 1-10.
- 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
Python function program to find the HCF of two numbers.
Python function program to create a function with *args as parameters.
Python function program to get the factorial of a given number.
Python function program to get the Fibonacci series up to the given number.
Python function program to get unique values from the given list.