Python Program to Add Two Numbers

Program Code

# take two inputs
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')

# add the inputs
sum = float(num1) + float(num2)

# display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))

Input Given:

Enter first number: 56
Enter second number: 65

Expected Output:

The sum of 56 and 65 is 121.0

Code Explanation

  1. We are taking two inputs from the user and storing them in the variables num1 and num2.
  2. We are converting the inputs to float and storing the result in the variable sum.
  3. We are printing the sum of the two numbers.

Leave a Comment

Share to...