To find largest or greatest of two numbers in python, you have to ask from user to enter the two numbers and then compare both the numbers with each other to find which one is largest and then display the largest number on the output screen as shown in the program given below.
Following python program ask from user to enter two numbers to find and print the largest one:
# Python Program - Find Largest of Two Numbers print("Enter 'x' for exit."); print("Enter any two numbers: "); num1 = input(); if num1 == 'x': exit(); else: num2 = input(); number1 = int(num1); number2 = int(num2); count = 0; if number1 > number2: largest = number1; count = 1; elif number1 < number2: largest = number2; count = 1; else: print("\nBoth the numbers are equal to each other."); if count == 1: print("\nLargest of the given two numbers is", largest);
Here is the sample run of the above Python program. This is the initial output asking to enter any two numbers to find which one is the largest number:
Now enter any two number say 10 and 20 and then press enter to find which one is largest from 10 and 20:
In case if user provide equal number or same number in both input say 10 as first number and 10 as second number too. Therefore, in this case, 10 is not greater than 10 or 10 is not larger than 10 as both the numbers are equal to each other. Therefore here is the sample run in this case:
You can also check it out, just by running the above program and supply same number say 10 as input in both case, that is for first and second number and then press enter key to see the above output.
Here is the same program with run on python shell:
You may also like to learn or practice the same program in other popular programming languages: