 In this article, we are going to write a Python program to add two numbers. Here we will see two ways to add two numbers first we assigned value to the variable and second, we will ask for value from the user and then add.

To understand this example you should have basic knowledge of Python Programming.

## How to add two numbers using Python?

Here we will add two numbers using two different ways, First is assigned by default value and the second is asked for value from the user.

### Example 1:

In this example, we have two values and a and b, and use the + operator to add these values.

``````# Assigned by default values to both a and b variables.
a = 12.12
b = 20.12

result = a + b
print("Output:- ", result)``````

Output

``````#Output of the above program will be:
Output:- 32.24``````

In the above program, we defined two variables a and b, and added both the variables using the + operator.

### Example 2:

In this example, we use the input() function to take input from the user and then convert that input to a floating-point number using the float() function. After converting we + operator to add two values.

``````
#Ask a and b value from the user using input() function
a = float(input("Enter first number:- "))
b = float(input("Enter second number:- "))

result = a + b
print("Output:- ", result)``````

Output

``````#Output of the above program will be:
Enter first number:- 12.30
Enter second number:- 12.40
Output:- 24.70``````