codescracker


python

Python Program to Find Largest of Three Numbers



« Previous Program Next Program »


Find Largest of Three Numbers in Python

To find largest or greatest of three numbers in python, you have to ask from user to enter three numbers to find and print the largest one among these three numbers as shown in the program given here.

Python Programming Code to Find Largest of Three Numbers

Following python program ask from user to enter any three numbers and then find the largest one:

# Python Program - Find Largest of Three Numbers

print("Enter 'x' for exit.");
print("Enter any three numbers: ");
num1 = input();
if num1 == 'x':
    exit();
else:
    num2 = input();
    num3 = input();
    number1 = int(num1);
    number2 = int(num2);
    number3 = int(num3);
    largest = number1;
    count = 1;
    if largest < number2:
        if number2 > number3:
            largest = number2;
        else:
            largest = number3;
    elif largest < number3:
        if number3 > number2:
            largest = number3;
        else:
            largest = number2;
    else:
        largest = number1;
    if number1 == number2:
        if number1 == number3:
            count = 0;
    if count == 0:
        print("\nAll numbers are equal to each other.");
    else:
        print("\nLargest of the given three numbers is",largest);

Here are some sample runs of the above python program illustrating how to find largest of three numbers.

If you run the above program, then you will find a output asking from the user to enter any three numbers as shown in the below screenshot:

find largest of three numbers python

Now let's enter any three numbers say 1, 2, 3 as first, second and third number and press enter key to find which one is largest:

print largest of three numbers python

Now let's re-run the same program and check with another sample run, this time provide 1, 3, 2 as first, second and third number and press enter to see the following output:

largest of three numbers python

Now again re-run the same program to check by giving largest number as first number and other two number as second and third one, say 3, 1, 2 and press enter to see the sample output given below:

largest among three numbers python

If user supplied all the three number with same value say 10, 10, 10 as all the three input number, then as you all know that all the three numbers, that is 10, 10 and 10 are equal to each other, therefore you will see that all the three numbers are equal to each other as output as shown in below sample run:

print largest number among three python

Here is the same program on python shell. This is first snapshot:

python find largest of three numbers

This is second snapshot:

find largest among three numbers in python

Program Video with Compile and Run

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »








Tools
Calculator

Quick Links
Signup - Login - Give Online Test