Smallest of three numbers

EasyIf-Else Programs · 61 of 64

Write a Python program to find the smallest of three numbers.

Advertisement
Input
A = 45, B = 23, C = 68
Output
Smallest: 23 | min(): 23

Approach

  1. Compare each with the other two using <=.

Solution

Python
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.

Advertisement

Learn the concept

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

More if-else programs

← All 64 If-Else Programs