Algorithm


1. Input:
   a. Get the first number as input and store it in a variable (num1).
   b. Get the second number as input and store it in another variable (num2).

2. Addition:
   a. Add num1 and num2, and store the result in a variable (sum).

3. Output:
   a. Display the sum as the result of adding num1 and num2.

Code Examples

#1 Code Example- Python Program Add Two Numbers

Code - Python Programming

# This program adds two numbers

num1 = 1.5
num2 = 6.3

# Add two numbers
sum = num1 + num2

# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
Copy The Code & Try With Live Editor

Output

x
+
cmd
The sum of 1.5 and 6.3 is 7.8

#2 Code Example- Python Program Add Two Numbers With User Input

Code - Python Programming

# Store input numbers
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')

# Add two numbers
sum = float(num1) + float(num2)

# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter first number: 1.5
Enter second number: 6.3
The sum of 1.5 and 6.3 is 7.8

#3 this addition in a single statement without using any variables as follows.

Code - Python Programming

print('The sum is %.1f' %(float(input('Enter first number: ')) + float(input('Enter second number: '))))
Copy The Code & Try With Live Editor

Output

x
+
cmd
Enter first number: 1.5
Enter second number: 6.3
The sum of 1.5 and 6.3 is 7.8
Advertisements

Demonstration


Python Programing Example to Add Two Numbers-DevsEnv