Skip to content
Home » Add Two Numbers using Function in Python

Add Two Numbers using Function in Python

Learn about Add Two Numbers using Function in Python in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.

Add Two Numbers using Function in Python

# Python program to add two numbers using function

def add_num(a,b):
    sum = a + b
    return sum

#taking input 
num1 = float(input('Enter first number : '))
num2 = float(input('Enter second number : '))

#function call
print('The sum of numbers {0} and {1} is {2}'.format(num1, num2, add_num(num1, num2)))

Output:

Enter first number : 8
Enter second number : 9
The sum of numbers 8.0 and 9.0 is 17.0

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Python Program to Add Two Numbers Provided by User