Python function program to add two numbers

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
  1. Create a function add.
  2. Use the def keyword to define the function.
  3. Pass two parameters i.e. numbers to the function.
  4. Add the numbers passed to the function using the” + ” operator.
  5. Print the output.
  6. 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

print the input string 10 times.

Leave a Comment