Skip to content
Programs · Program 6-4

Q.Program 6-4: Program to find the larger of the two pre-specified numbers.

Rajasthan RbseTextbookSubjective· 2mImportance★★★★★est
21% · 8/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 →

Store the two numbers in variables, compare them with a relational operator inside an if…else, and print the branch that matches — with 5 and 6 the program reports that 6 (the second number) is larger.

The idea. When a program must choose between two courses of action based on a condition, selection (if…else) is the right construct: the relational expression num1 > num2 evaluates to a Boolean, and exactly one of the two blocks executes.

# Program 6-4: find the larger of two pre-specified numbers
num1 = 5
num2 = 6
if num1 > num2:
    print("The first number", num1, "is larger")
else:
    print("The second number", num2, "is larger")

Expected output

The second number 6 is larger

How it works, line by line

  • num1 = 5 and num2 = 6 are the pre-specified numbers — no input() is needed; the values are fixed in the code.
  • if num1 > num2: evaluates 5 > 6, which is False.
  • Because the condition failed, Python skips the if block and executes the else block, printing that the second number is larger. …

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.