Add Two Numbers in Python – Step by Step Guide

Adding two numbers is one of the most basic programs in Python. This guide explains it professionally in English with small Hinglish notes for better understanding.

Program

# Prompt the user to enter the first number
num1 = int(input("Enter first number: "))

# Prompt the user to enter the second number
num2 = int(input("Enter second number: "))

# Add the two numbers
sum = num1 + num2

# Display the sum
print("The sum is:", sum)

Example Run

Enter first number: 10
Enter second number: 15
The sum is: 25

Program Explanation

  1. Use input() to take input from the user.
    User se input lene ke liye input() use karein.
  2. Convert the input to integer using int().
    Input ko integer me convert karne ke liye int() use karein.
  3. Store the first number in num1.
    Pehla number num1 me store karein.
  4. Store the second number in num2.
    Dusra number num2 me store karein.
  5. Add num1 and num2 and store in sum.
    num1 aur num2 ko add karke sum me store karein.
  6. Print the sum using print().
    Sum ko print() se screen par dikhaayein.

Algorithm – Step by Step

  1. Start the program.
    Program start karein.
  2. Prompt the user to enter the first number and store it.
    User se pehla number maangkar store karein.
  3. Prompt the user to enter the second number and store it.
    User se dusra number maangkar store karein.
  4. Add the two numbers using the + operator.
    Dono numbers ko + se add karein.
  5. Display the sum on the screen.
    Sum ko screen par dikhaayein.
  6. End the program.
    Program ko end karein.

Flowchart

   ┌───────────┐
   │   Start   │
   └─────┬─────┘
         │
         ▼
 ┌─────────────────┐
 │ Input num1      │
 └─────┬───────────┘
       │
       ▼
 ┌─────────────────┐
 │ Input num2      │
 └─────┬───────────┘
       │
       ▼
 ┌─────────────────┐
 │ sum = num1 + num2│
 └─────┬───────────┘
       │
       ▼
 ┌─────────────────┐
 │ Print sum       │
 └─────┬───────────┘
       │
       ▼
   ┌───────────┐
   │   End     │
   └───────────┘