Python Program To Add Two Numbers With User Input

Python program to add two numbers with user input is provided on this page.

Python Program To Add Two Numbers With User Input

Program 1

In this python program, we simply accept two numbers from user using input() function. Then we convert those numbers to floating points because input() takes it as string.


# two variable to store two input numbers
first_number = input('Enter first number: ')
second_number = input('Enter second number: ')
# add two numbers
sum = float(first_number) + float(second_number)
# Display the sum
print('The sum of {0} and {1} is {2}'.format(first_number, second_number, sum))

Program 2

Another way is one liner to python program to add two numbers.

This is very simple and efficient but complex way of doing addition of two numbers in python.


print('The sum is %.1f' %(float(input('Enter first number: ')) + float(input('Enter second number: '))))

Related Python Programs

Which of following is not keyword
Lists
What is tail recursion

Comments