• We just launched and are currently in beta. Join us as we build and grow the community.

How to Find the Largest Among Three Numbers in Python

Stefan Da Man

Meme Archivist
S Rep
0
0
0
Rep
0
S Vouches
0
0
0
Vouches
0
Posts
122
Likes
179
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
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. print

    (

    "\n

    \n

    =============== Find the Largest Among Three Numbers in Python ===============\n

    \n

    "

    )


  4. num1 =

    int

    (

    input

    (

    "Enter number 1: "

    )

    )
  5. num2 =

    int

    (

    input

    (

    "Enter number 2: "

    )

    )
  6. num3 =

    int

    (

    input

    (

    "Enter number 3: "

    )

    )

  7. print

    (

    "\n

    My current numbers: %d, %d, %d"

    % (

    num1,

    num2,

    num3)

    )
  8. print

    (

    "\n

    "

    )


  9. if

    (

    num1 >=

    num2)

    and

    (

    num1 >=

    num3)

    :
  10. largest =

    num1
  11. elif

    (

    num2 >=

    num1)

    and

    (

    num2 >=

    num3)

    :
  12. largest =

    num2
  13. else

    :
  14. largest =

    num3

  15. print

    (

    "The largest number is"

    ,

    largest)


  16. user_input=

    input

    (

    "\n

    \n

    Try Again? (Yes/No): "

    )
  17. if

    user_input.lower

    (

    )

    ==

    'no'

    :
  18. print

    (

    "Exit program."

    )
  19. break

  20. elif

    user_input.lower

    (

    )

    ==

    'yes'

    :
  21. ret=

    True

  22. else

    :
  23. print

    (

    "Wrong input."

    )
  24. ret=

    True


  25. if

    ret:
  26. 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:

how-to-find-the-largest-among-three-numbers-in-python-1.png

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


Download
You must upgrade your account or reply in the thread to view hidden text.
 

442,401

317,942

317,951

Top