Python Practice › If-Else Programs › Program 61
Smallest of three numbers
Write a Python program to find the smallest of three numbers.
Input
A = 45, B = 23, C = 68
Output
Smallest: 23 | min(): 23
Approach
- Compare each with the other two using
<=.
Solution
a, b, c = 45, 23, 68if a <= b and a <= c: smallest = aelif b <= c: smallest = belse: smallest = cprint("Smallest:", smallest, "| min():", min(a, b, c))Output
Smallest: 23 | min(): 23
Line by line
Line 4
If a is not the smallest, only b and c remain to compare.
Learn the concept
New to this topic? Read the lesson, then come back.