Program to add two numbers using functions in Python
In this python programming article, we are going to learn
-
program to add two numbers using function in python
Program to find the sum of two numbers using functions in Python
The addition program in python using function to find the sum of two numbers is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
# Function Body
def add_numbers(n1,n2):
sum_of_numbers = n1 + n2
return sum_of_numbers
# Main Body
if __name__ == "__main__":
a = float(input("Enter first number: ")).strip()
b = float(input("Enter second number: ")).strip()
addition = add_numbers(a,b)
print("The sum is",addition)
The output of the program to add two numbers using function in python is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter first number: 23
Enter second number: 12
The sum is 35.0
Few important tips about the program
1. def keyword is used to define a function.
2. The variables n1 and n2 are called the parameters to a function.
3. The value which are passed to the parameters are known as arguments.
4. if __name__ == "__main__" is used to tell the python interpreter that our program starts from there. It is like the main() function in C or public static void main(String args[]) in Java.
Write a program to add two numbers using function in python.
This wraps up our session on python program to add two numbers using functions.
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :
Published Date :
Dec 01,2021