Python Program to find the Biggest and Smallest of 3 numbers

Hello people, here we discuss a simple python program which finds the biggest and smallest number out of given three numbers. Here we use concept of functions in this program.

We use two functions biggest() and smallest() to find the biggest number and smallest number respectively and finally return the result.

Program on Github

Biggest and Smallest – Code Visualization

Task :

To find smallest and biggest number out of given 3 numbers.

Approach :

  • Read 3 input numbers using input() or raw_input().
  • Use two functions largest() and smallest() with 3 parameters as 3 numbers
  • largest(num1, num2,  num3)
    • check if num1 is larger than num1 and num2, if true num1 is largest, else
    • check if num2 is larger than num1 and num3, if true num2 is largest,
    • if both the above fails, num3 is largest
    • Print the largest number
  • smallest(num1, num2,  num3)
    • check if num1 is smaller than num1 and num2, if true num1 is smallest, else
    • check if num2 is smaller than num1 and num3, if true num2 is smallest,
    • if both the above fails, num3 is smaller
    • Print the smallest number

Program on Github

Program :

 

Output :

Biggest and Smallest number - programminginpython.com
Biggest and Smallest number – programminginpython.com
Biggest and Smallest number - programminginpython.com
Biggest and Smallest number – programminginpython.com

Program on Github

3 Comments

  1. Emad

    def sort3(a,b,c):
    … if a>b:
    … a,b=b,a
    … if a>c:
    … a,c=c,a
    … if b>c:
    … b,c=c,b
    … return a,b,c

    print(‘biggest is {} and smallest is {}’.format(sort3(5,8,1)[-1], sort3(5,8,1)[0]))

    1. avinash

      Hey much much better than the one here.

      But if u see all the posts here, there are different versions of same post.
      For ex : for finding reverse there are 3 variations here ( using slice, hard way using operators, using reversed function) similary this post will have some variations and i will make sure to post the way you suggested.

  2. sana

    Create variables to keep track of the range of values that the square root must be within. Initially, this range will be between zero and the number you are trying to square root
    “Guess” that the number in the middle of this range might be the square root
    Try multiplying this guess by itself to see if it is larger, or smaller, than the real square root
    Adjust the range of possible values and repeat the whole process a few thousand times… can anybody solve this question

Leave a Reply