Algorithm


Input: num1, num2, num3

If num1 > num2:
    If num1 > num3:
        Largest = num1
    Else:
        Largest = num3
Else:
    If num2 > num3:
        Largest = num2
    Else:
        Largest = num3

Output: Largest

How do you find the greatest number in Python?

In Python, you can find the greatest number among a set of numbers using the max() function. Here's an example:

python
numbers = [4, 7, 1, 9, 12, 5] greatest_number = max(numbers) print("The greatest number is:", greatest_number)

In this example, the max() function takes the list of numbers as an argument and returns the maximum value. You can replace the numbers list with any other list of numeric values that you want to find the greatest number from.

Alternatively, if you have a variable number of arguments, you can use the max() function with the *args syntax:

python
numbers = (4, 7, 1, 9, 12, 5) greatest_number = max(*numbers) print("The greatest number is:", greatest_number)

In this case, the *numbers syntax unpacks the tuple into individual arguments for the max() function.

 

 

 

Code Examples

#1 Example-python largest number

Code - Python Programming


# Python program to find the largest

def maximum(x, y, z):

    if (x >= y) and (x >= z):

        largest = x

    elif (y >= x) and (y >= z):

        largest = y

    else:

        largest = z

    return largest

Output:

Let us consider the values x=2, y=5, and z=8:

largest=8
Copy The Code & Try With Live Editor

Output

x
+
cmd
Let us consider the values x=2, y=5, and z=8 then
largest=8

#2 Code Example with Python Programming

Code - Python Programming


def maximum(x, y, z):

    list = [x, y, z]

    return max(list)
Copy The Code & Try With Live Editor

Output

x
+
cmd
Let us consider the values x=2, y=5, and z=8 then
largest=8

#3 Example- Return the greatest of the three numbers.

Code - Python Programming


x=2

y=5

z=8

print(max(x, y, z))
Copy The Code & Try With Live Editor

Output

x
+
cmd
8

#4 Python largest number.

Code - Python Programming


print "max (70, 900, 3000) :"

print "max (222, 45, 80) :"

print "max (70, 9040, 700) :"

print "max (7022, 9020, 300) :"

print "max (5555, 900, 6) :"

Output:

print "max (70, 900, 3000) : 3000

print "max (222, 45, 80) : 222

print "max (70, 9040, 700) : 9040

print "max (7022, 9020, 300) : 9020

print "max (5555, 900, 6) :"- 5555
Copy The Code & Try With Live Editor

#5 By using the sort function

Code - Python Programming


lis = [100, 43, 400, 63, 65]

lis.sort()

print("Largest number in the list is:", lis[-1])
Copy The Code & Try With Live Editor

Output

x
+
cmd
The largest number in the list is 400

#6 With the help of the max()

Code - Python Programming


lis = [100, 43, 400, 63, 65]

print("Largest number in the list is:", max (lis))

Output:

The largest number in the list is 400
Copy The Code & Try With Live Editor
Advertisements

Demonstration


Python Programing Example to Find the Largest Among Three Numbers-DevsEnv