Larger of two numbers

EasyIf-Else Programs · 22 of 64

Write a Python program to print the larger of two numbers.

Advertisement
Input
25, 63
Output
63

Approach

  1. Compare them with >; handle equal numbers too.

Solution

Python
a, b = 25, 63if a > b:    print(a)elif b > a:    print(b)else:    print("Both are equal:", a)
Output
63

Line by line

Lines 6-7

Equal numbers get their own message.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More if-else programs

← All 64 If-Else Programs