1. Python

Adding Numbers | Python

Python Program to add two Numbers

# Python Program for adding Numbers
num1 = 19.2
num2 = 12.1

# Adding Two Numbers
sum = num1 + num2

# Printing Sum of numbers
print('Sum of two numbers {0} and {1} is {2}'.format(num1, num2, sum))

Output

Sum of two numbers 19.2 and 12.1 is 31.299999999999997

Adding Two Numbers Inputed By User

# Python Program for adding Numbers taking input from User
num1 = input("Enter first number => ")
num2 = input("Enter second number => ")

# Adding Two Numbers inputted by User
sum = float(num1) + float(num2)

print('Sum of two numbers {0} and {1} is {2}'.format(num1, num2, sum))

Output

Enter first number => 10
Enter second number => 2
Sum of two numbers 10 and 2 is 12.0

In the above Python, float(num1) and float(num2) is used as input() function always take in value as a String, but for adding Number is required.

More About Python

Comments to: Adding Numbers | Python

Your email address will not be published.

Ads