Python Program to Add Two Numbers

Adding numbers is a fundamental operation in any programming language, including Python. Python provides a simple and intuitive way to add numbers using the built-in + operator. Whether you’re working with integers or floating-point numbers, Python’s arithmetic capabilities make it easy to add them together. In this article, we will explore how to add numbers in Python, covering basic arithmetic operations, input and output methods, and practical examples to help you gain a better understanding of how to add numbers in Python

Adding two Integers

num1 = 10
num2 = 20
sum = num1 + num2
print("The sum of", num1, "and", num2, "is", sum)

Output: The sum of 10 and 20 is 30

Adding two floating-point numbers:

num1 = 3.14
num2 = 2.71
sum = num1 + num2
print("The sum of", num1, "and", num2, "is", sum)

Output: The sum of 3.14 and 2.71 is 5.85

Adding numbers using input():

num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
sum = num1 + num2
print("The sum of", num1, "and", num2, "is", sum)

Output

Enter first number: 4.5
Enter second number: 5.5
The sum of 4.5 and 5.5 is 10.0

Leave a Comment