Python program to add two numbers

Description: Write a Python program that takes two numbers from the user and prints their sum.

Rules and hints:

  • Use input() to read the numbers.
  • input() gives a string, so convert it with int() (or float() for decimals).

Python program to add two numbers

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

total = num1 + num2
print("Sum =", total)

Output:

Tutorials Class - Output Window

Enter first number: 12
Enter second number: 8
Sum = 20

How it works

  • The two input() calls read what the user types, as text.
  • int() converts the text to a whole number. Without it, "12" + "8" would give 128.
  • The sum is stored in total and printed.

Learn more in Python input() Function and Python Type Casting.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.