Takes three numbers as arguments and returns the largest of them

Takes three numbers as arguments and returns the largest of them.

Use of min() and max() in Python 

User can enter any three numbers from key-board and then we can find that among that three number which is greatest number. If you want find least number then also you can find.

Aim: A function max_of_three() that takes three numbers as arguments and returns the largest of them.

Algorithm:

Step1. start

Step2. define max function

Step3. In max function read a, b, c

 

Step4. check the condition a>b and a>c Step5.

If the condition is true return a

Step6. Otherwise check the condition b>c

Step7. If the condition is true return b Otherwise return c

Step8. declare  the variables a,b,c and read them.

Step9. Print the largest of three  numbers.

Step10. End   Program: def max(a,b,c):

if (a>b and a>c):

return a

elif(b>c):

return b

else:

return c

a=int(input(‘enter a:’))

b=int(input(‘enter b:’))

c=int(input(‘enter c:’))

ans=max(a,b,c)

print(‘largest of three numbers=’, ans)  

Output:

>>>

enter a:23

enter b:56

enter c:13

largest of three numbers= 56

>>

Related Link:

Takes three numbers as arguments and returns the largest of them To know more lager number click on wikipedia

Python | Maximum and Minimum in a Set

Leave a Comment

Your email address will not be published. Required fields are marked *