Python program to find smallest number among three

In this tutorial, we are going to learn a python program to find the smallest number among three numbers that are given by the user.

Problem Statement

For three numbers that are inputs given by the user, we have to print the smallest among those 3 numbers.

 For example:

Case1: If the user inputs the numbers 12, 25, and 11

              then the output should be ‘11’.

Case2: If the user inputs the numbers 51, 100, and 21.

            then the output should be ‘21’.

Our Logic to find smallest number among three

  • Our program will take 3 integer inputs from the user.
  • The inputs are then compared to each other using ‘logical conditions’.
  • And using ‘conditional statement’, the output will be printed.

Algorithm to find smallest number among three

Step 1: Start

Step 2: take input from the user.

Step 3: if a<=b and a<=c:

                       Print “a is smallest”

elif b<=a and b<=c:

                       print “b is smallest”

elif c<=a and c<=b:

                        print “c is smallest”

Step 4: Stop

Python program to find smallest number among three

Output 1:

python code to find smallest among three

Explanation:

The user inputs the integers 9, 8, 1. For these inputs, our program is comparing all three integer inputs with each other to find which one is the smallest.

Let’s have a look at the conditions of conditional statements in this output:

9<=8 and 9<=1, returns ‘False’

8<=9 and 8<=1, returns ‘False’

1<=9 and 1<8, returns ‘True’

So the output generated is 1 which is the value of ‘c’.

Output 2:

Explanation:

The user inputs the integers 11, 19, 51. For these inputs, our program is comparing all three integer inputs with each other to find which one is the smallest.

Let’s have a look at the conditions of conditional statements in this output:

11<=19 and 11<=51, returns ‘True’

19<=11 and 19<=51, returns ‘False’

51<=11 and 51<19, returns ‘False’

So the output generated is 11 which is the value of ‘a’.