Python Program to Add Two Numbers
This python program adds two numbers given by user and displays the output.
In this python example, we first read two number from user using built-in function
input(). Since function
input() returns string value, we need to convert them to number type. And then, given numbers are added simply by
Python Source Code: Add Two Numbers
# Python program to find # sum of two numbers # Reading two numbers number1 = input('Enter first number: ') number2 = input('Enter second number: ') # Converting to float # Conversion is required because # input() function return string number1 = float(number1) number2 = float(number2) # Addition result = number1 + number2 # Displaying result print('Sum of %0.2f and %0.2f is %0.2f' % (number1, number2, result))
Enter first number: 12.23 Enter second number: 23.45 Sum of 12.23 and 23.45 is 35.68