Skip to content
Programs · Program 5-4

Q.Program 5-4: Write a Python program to find the sum of two numbers.

Punjab PsebTextbookSubjective· 2mImportance★★★★★est
16% · 8/49 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Keep the two numbers in variables, add them with the + operator, and print the result — 10 + 20 = 30.

The idea. Addition of two numbers is the classic first arithmetic program: two values, one operator, one output. Storing the operands in named variables lets the print() show the inputs and the answer, which is good practice for readable output.

Program

# prog5-4.py
# Program to find the sum of two numbers
num1 = 10
num2 = 20
total = num1 + num2
print("The sum of", num1, "and", num2, "is", total)

Expected output

The sum of 10 and 20 is 30

Key lines

  • num1 = 10 and num2 = 20 store the operands. Both are int, so num1 + num2 is exact integer addition giving the int 30.
  • total = num1 + num2 performs the computation once and names the result.
  • The print() uses commas, so every item is separated by one space in the output. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.