In this python function program, we will create a function to add two numbers.
What is Function?
It is a block of code that executes when it is called.
To create a function we use def keyword.
Steps to solve the program
- Create a function add.
- Use the def keyword to define the function.
- Pass two parameters i.e. numbers to the function.
- Add the numbers passed to the function using the” + ” operator.
- Print the output.
- Pass the numbers to the function while calling the function.
def add(a,b):
total = a+b
print("Total: ",total)
num1 = int(input("Enter number 1: "))
num2 = int(input("Enter number 2: "))
add(num1,num2)
Output :
Enter number 1: 10
Enter number 2: 20
Total: 30
Related Articles
Python function program to print the input string 10 times.
Python function program to print a table of a given number.
Python function program to find the maximum of three numbers.
Python function program to find the sum of all the numbers in a list.
Python function program to multiply all the numbers in a list.
Python function program to reverse a string.
print the input string 10 times.