Skip to content
Programs · Program 6-1

Q.Program 6-1: Program to print the difference of two numbers.

Sikkim CbseNCERTSubjective· 2mImportance★★★★★est
5% · 2/39 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 →

A straight-line (sequential) program: read two integers, compute diff = num1 - num2, print it — with no selection, so the difference may come out negative.

The idea. Program 6-1 is the chapter's baseline example of sequential flow: statements executing top to bottom with no branching. It reads two numbers, subtracts, prints. Its deliberate limitation — subtracting in fixed order — is what motivates the if–else version (Program 6-2, positive difference) introduced right after.

Program

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

diff = num1 - num2
print("The difference of", num1, "and", num2, "is", diff)

Sample runs

Enter first number: 10
Enter second number: 5
The difference of 10 and 5 is 5
Enter first number: 5
Enter second number: 10
The difference of 5 and 10 is -5

Key lines. Both inputs pass through int() because input() returns strings — without the conversion, "5" - "10" would raise a TypeError (there is no subtraction for strings). The print uses comma-separated items, so Python inserts the spaces automatically. …

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.