Python Program to Add Two Numbers
ⓘ Sponsored by 10xer.co
Addition is a math operation that calculates the sum of two or more numbers. It is denoted by the plus symbol (+). For example, 2 + 3 = 5
Python Code :
The below Python program takes two numbers as input from the user, adds them, and prints the result:
num1 = float(input("Enter first number: ")) # convert input to float for decimal values
num2 = float(input("Enter second number: "))
result = num1 + num2
print("The sum of", num1, "and", num2, "is", result)
This program prompts the user to enter two numbers as input, converts them to float data type (in case the user enters decimal values), adds the two numbers, and prints the result.
You can save this code as a file with a .py extension (e.g. add_two_numbers.py) and run it using Python. Alternatively, you can run the code in the Python interpreter directly by typing the code line by line in the terminal or command prompt.
ⓘ Sponsored by 10xer.co