How to Find the Largest Among Three Numbers in Python

In this tutorial, we will program 'How to Find the Largest Among Three Numbers in Python'. We will gain a better understanding of finding the largest number among three given numbers. The main goal here is to use a method that will provide accurate results. I will provide a sample program to demonstrate the actual coding of this tutorial.

This topic is very easy to understand; just follow the instructions I provide, and you can also do it yourself with ease. The program I will show you covers the basics of programming for finding the largest number. I will do my best to provide you with the easiest method of creating this program, called 'Finding the Largest Number'. So, let's start with the coding.

Getting Started:

First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.

Creating Main Function

This is the main function of the application. The following code will display a simple GUI in terminal console that will find the largest number. To do this, simply copy and paste these blocks of code into the IDLE text editor.
  1. while True:
  2.    ret=False
  3.  
  4.    print("\n\n=============== Find the Largest Among Three Numbers in Python ===============\n\n")
  5.  
  6.  
  7.    num1 = int(input("Enter number 1: "))
  8.    num2 = int(input("Enter number 2: "))
  9.    num3 = int(input("Enter number 3: "))
  10.    
  11.    print("\nMy current numbers: %d, %d, %d" % (num1, num2, num3))
  12.    print("\n")
  13.    
  14.  
  15.    if (num1 >= num2) and (num1 >= num3):
  16.       largest = num1
  17.    elif (num2 >= num1) and (num2 >= num3):
  18.       largest = num2
  19.    else:
  20.       largest = num3
  21.  
  22.    print("The largest number is", largest)
  23.  
  24.  
  25.    user_input=input("\n\nTry Again? (Yes/No): ")
  26.    if user_input.lower()=='no':
  27.       print("Exit program.")
  28.       break
  29.  
  30.    elif user_input.lower()=='yes':
  31.       ret=True
  32.  
  33.    else:
  34.       print("Wrong input.")
  35.       ret=True
  36.  
  37.  
  38.    if ret:
  39.       continue

In the provided code, we simply enclosed the code with a while loop to allow for continuous execution of the program. Then, we set three variables for the inputs that contain different ranges of numbers so that we can determine the largest number. To find the largest, we simply use a conditional statement with the arguments of the less than and greater than operators.

Output:

The How to Find the Largest Among Three Numbers in Python source code that I provide can be download below. Please kindly click the download button.

There you have it we successfully created How to Find the Largest Among Three Numbers in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for Python Language

Python Tutorials

Add new comment