How to add two numbers in python?

 What is Python?

Python is a popular programming language. It was created by Guido van Rossum, and released in 1991.

  • web development (server-side),
  • software development,
  • mathematics,
  • system scripting.
Steps:

Given two numbers num1 and num2. The task is to write a Python program to find the addition of these two numbers.

In the below program to add two numbers, the user is first asked to enter two numbers and the input is scanned using the input() function and stored in the variables number1 and number2. Then, the variables number1 and number2 are added using the arithmetic operator + and the result is stored in the variable sum.

Below is the Python program to add two numbers:

Example:

# Python3 program to add two numbers


num1 = 15

num2 = 12


# Adding two nos

sum = num1 + num2


# printing values

print("Sum of {0} and {1} is {2}" .format(num1, num2, sum))

Example 2:

# Python3 program to add two numbers

number1 = input("First number: ")
number2 = input("\nSecond number: ")

# Adding two numbers
# User might also enter float numbers
sum = float(number1) + float(number2)

# Display the sum
# will print value in float
print("The sum of {0} and {1} is {2}" .format(number1, number2, sum))

Comments

Popular posts from this blog

proassignment help backlink data index 41

Programming shark backlink data index 67

programming shark backink data index 31