How to Find the Largest Among Three Numbers using Python?

PythonProgramming

You can create a list of the three numbers and call the max method to find the largest among them.

 example

my_list = [10, 12, 3]
print(max(my_list))

Output

This will give the output −

12

Example

If you want to calculate it yourself, you can create a simple function like

def max_of_three(a, b, c):
   if a > b and a > c:
      return a
   elif b > c:
      return b
   else:
      return c
print(max_of_three(10, 12, 3))

Output

This will give the output −

12
raja
Published on 20-Apr-2018 07:53:38
Advertisements