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.

#### 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 :

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
number1 = int(input('Enter First number : ')) number2 = int(input('Enter Second number : ')) number3 = int(input('Enter Third number : ')) def largest(num1, num2, num3): if (num1 > num2) and (num1 > num3): largest_num = num1 elif (num2 > num1) and (num2 > num3): largest_num = num2 else: largest_num = num3 print("The largest of the 3 numbers is : ", largest_num) def smallest(num1, num2, num3): if (num1 < num2) and (num1 < num3): smallest_num = num1 elif (num2 < num1) and (num2 < num3): smallest_num = num2 else: smallest_num = num3 print("The smallest of the 3 numbers is : ", smallest_num) largest(number1, number2, number3) smallest(number1, number2, number3) |

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]))

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.

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