In this python program, we discuss a simple python program which finds the biggest and smallest number out of given three numbers. Here we use elif statement to compare 3 numbers and find biggest and smallest numbers out of them.
Problem Statement:
To find smallest and biggest number out of given 3 numbers.
Program Logic:
- Take 3 numbers as input from user using input method
- Compare three numbers to find maximum and minimum number among them using if-else block
- Display the biggest and smallest number
This are the steps which we are going to follow to execute the above program.
Python program to find Biggest/Largest of 3 numbers
In this Python Program to Find Largest of Three numbers, the following statements ask the user to enter three numbers and stores the user entered values in variables num1,num2 and num3

Within this python program, the First if condition check whether num1 is greater than num2 and num1 is greater than num3. If both of these are True then following print statement will be displayed (num1 is greater than both num2, num3).

First python elif statement check whether num2 is greater than num1 and num2 is greater than num3. If both of these are True then following print statement will be displayed “num2 is greater than both num1 and num3”.

Second Elif statement check whether num3 is greater than num1 and num3 is greater than num2. If both of these are True then following print statement will be displayed “num3 is greater than both num1 and num2.

If all the above conditions fail, it means they are equal.

Below is complete source code with output

Python program to find Smallest of 3 numbers
In this Python Program to Find smallest of Three numbers, the following statements ask the user to enter three numbers and stores the user entered values in variables num1,num2 and num3
num1 = float(input("Enter the First value: ")) num2 = float(input("Enter the Second value: ")) num3 = float(input("Enter the Third value: "))
Within this python program, the First if condition check whether num1 is smaller than num2 and num1 is smaller than num3. If both of these are True then following print statement will be displayed “num1 is smaller than both num2, num3”
if (num1 < num2 and num1 < num3): print(num1," is Smaller Than both", num2 ,"and" ,num3) elif (num2 < num1 and num2 < num1): print(num2, "is Smaller Than both", num1," and ",num3) elif (num3 < num1 and num3 < num2): print(num3,"is Smaller Than both",num1," and",num2) else: print("Either any two values or all the three values are equal")
First python elif statement check whether num2 is smaller than num1 and num2 is smaller than num3. If both of these are True then following print statement will be displayed “num2 is smaller than both num1 and num3”.
Second Elif statement check whether num3 is smaller than num1 and num3 is smaller than num2. If both of these are True then following print statement will be displayed “num3 is smaller than both num1, num2”
If all the above conditions fail, it means they are equal.
Below is Complete source code with output

Lets combine both source code together to find largest and smallest of 3 number using user defined function
Python program to find biggest and smallest of 3 numbers using function
This largest and smallest of three numbers python program helps the user to enter three different values and find the largest and smallest number among that three numbers using user defined function
We use two functions biggest()
and smallest()
to find the biggest number and smallest number respectively and finally display the result.
Below is complete source code

Here, we ask the user to enter 3 numbers. we call largest() which is user defined function and pass 3 numbers as an argument to it . Python cursor will jump to largest () function and copy all 3 numbers to variables say num1,num2,num3. then it will invoke largest function body and test all condition. If Given condition is valid then it will print largest number on the console
Python cursor will pass to main function body and execute smallest() function which is user defined function too. We will pass 3 number that we have taken from user to smallest() function . Smallest() function call called function and copy all numbers to local variables. After that it will invoke smallest function body to test the given condition. If condition is valid then it will print smallest numbers on output. I already explained the logic behind if – elif statement to execute the programs.
Output
