Python Programming: Adding Two Numbers with Ease

Example

Input 
enter the first number 5
enter the second number 6
Output
The sum is 11

Required to know

Use of Variables, Use of different operators like assignment or arithmetic operators, and Use of functions like print(), and input(), and Use of Data types.

Steps

  1. Take two numbers as input from the user.

  2. Use the arithmetic operator addition (+), to perform the sum of two numbers.

  3. Print the result.

Program

Case 1: - User Input

# This program prints the sum of two numbers.
# Get the first number from the user.
num_1 = int(input("Enter the first number: "))
# Get the second number from the user.
num_2 = int(input("Enter the second number: "))
# Calculate the sum of the two numbers.
sum = num_1 + num_2
# Print the sum.
print("The sum of the two numbers is:", sum)

Case 2: - Value already allocated

num_1 = 5  # The first number is assigned to the variable `num_1`.
num_2 = 6  # The second number is assigned to the variable `num_2`.
sum = num_1 + num_2  # The sum of the two numbers is assigned to the variable `sum`.
print("The sum is", sum)  # The sum is printed to the console.