Python Program to Add Two Numbers.

Given two numbers num1 and num2. Write a Python program to perform the addition of given two numbers and print the output sum.

Example:

Given: num1 = 10, num2 = 20
Output: 30

Given: num1 = 5, num2 = 8
Output: 13


Example Python Code:

# take input from the user
num1 = input("Enter a number: ")
num2 = input("Enter another number: ")

# add the two numbers
sum = float(num1) + float(num2)

# print the result
print("The sum of {0} and {1} is {2}".format(num1, num2, sum))
Output:
Enter a number: 12
Enter another number: 41
The sum of 12 and 41 is 53.0

Explanation:
This program takes two numbers as input from the user using the input() function, which returns the input as a string. The input is then converted to a float using the float() function so that the numbers can be added together. 

The result is stored in the variable sum, which is then printed out using the print() function. The format() method places the values of num1, num2, and sum into the string.

⚡ Please share your valuable feedback and suggestion in the comment section below or you can send us an email on our offical email id ✉ algolesson@gmail.com. You can also support our work by buying a cup of coffee ☕ for us.

Similar Posts

No comments:

Post a Comment


CLOSE ADS
CLOSE ADS