Programs · Program 6-4
Q.Program 6-4: Program to find the larger of the two pre-specified numbers.
Telangana TsbieTextbookSubjective· 2mImportance★★★★★est
21% · 8/39 Questions
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 = 5andnum2 = 6are the pre-specified numbers — noinput()is needed; the values are fixed in the code.if num1 > num2:evaluates5 > 6, which isFalse.- Because the condition failed, Python skips the
ifblock and executes theelseblock, 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.