Python program to add two number
In the program below, we've used the + operator to add two numbers.
Example 1 :
# This program adds two numbers
num1 = 4
num2 = 2
# Add two numbers
sum = num1 + num2
# Display the sum
print(sum)
Output :
6
Example 2:
# 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(num1 + " + " + num2 " = " sum)
Output :
Enter first number: 4
Enter second number: 5
4 + 5 = 9
In this program, we asked the user to enter two numbers and this program displays the sum of two numbers entered by user.
We use the built-in function input() to take the input. Since, input() returns a string, we convert the string into number using the float() function. Then, the numbers are added.
Hence proved, python is best
ردحذفNicely explained 🙂👍
ردحذفإرسال تعليق