{"id":6822,"date":"2023-10-31T17:17:34","date_gmt":"2023-10-31T11:47:34","guid":{"rendered":"https:\/\/python-programs.com\/?p=6822"},"modified":"2023-11-10T12:08:51","modified_gmt":"2023-11-10T06:38:51","slug":"python-program-to-find-the-largest-among-three-numbers","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-the-largest-among-three-numbers\/","title":{"rendered":"Python Program to Find the Largest Among Three Numbers"},"content":{"rendered":"
Given three numbers the task is to find the largest number among the three numbers.<\/p>\n
Prerequisite:<\/strong><\/p>\n Python IF…ELIF…ELSE Statements<\/strong><\/a><\/p>\n Explore more instances related to python concepts from Python Programming Examples<\/a> Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n Examples:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to determine the largest among the three numbers:<\/p>\n The three numbers are stored in number 1, number 2, and number 3, in that order. We use the if…elif…else ladder to find and show the largest of the three.<\/p>\n Here we compare one number with other two numbers using if..elif…else ladder.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We can directly use max function to know the largest number among the three numbers.<\/p>\n We provide the given three numbers as arguments to max function and print it.<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Given three numbers the task is to find the largest number among the three numbers. Prerequisite: Python IF…ELIF…ELSE Statements Explore more instances related to python concepts from Python Programming Examples Guide and get promoted from beginner to professional programmer level in Python Programming Language. Examples: Input: number1 = 3 number2 = 5 number3 = 7 …<\/p>\nnumber1 = 3\r\nnumber2 = 5\r\nnumber3 = 7<\/pre>\n
The largest number among the three numbers = 7<\/pre>\n
number1 = 9\r\nnumber2 = 9\r\nnumber3 = 2<\/pre>\n
The largest number among the three numbers = 9<\/pre>\n
Determine the largest of three numbers<\/h2>\n
\n
Method #1 :Using Conditional Statements<\/h3>\n
# function which returns the largest number among the three numbers\r\ndef findLargest(number1, number2, number3):\r\n # comparing first number with other two numbers\r\n if (number1 >= number2) and (number1 >= number3):\r\n return(number1)\r\n # comparing second number with other two numbers\r\n elif (number2 >= number1) and (number2 >= number3):\r\n return(number2)\r\n else:\r\n return(number3)\r\n\r\n\r\nnumber1 = 3\r\nnumber2 = 5\r\nnumber3 = 7\r\n# passing the three numbers to find largest number among the three numbers\r\nprint(\"The largest number among the three numbers =\",\r\n findLargest(number1, number2, number3))\r\n<\/pre>\n
The largest number among the three numbers = 7<\/pre>\n
Method #2: Using max function<\/h3>\n
number1 = 3\r\nnumber2 = 5\r\nnumber3 = 7\r\n# using max function to find largest numbers\r\nmaxnum = max(number1, number2, number3)\r\nprint(\"The largest number among the three numbers =\",\r\n maxnum)<\/pre>\n
The largest number among the three numbers = 7<\/pre>\n
Method #3: Converting the numbers to list and using max function to print max element of list<\/h3>\n
\n
number1 = 3\r\nnumber2 = 5\r\nnumber3 = 7\r\n# converting given 3 numbers to list\r\nlistnum = [number1, number2, number3]\r\n# using max function to find largest numbers from the list\r\nmaxnum = max(listnum)\r\nprint(\"The largest number among the three numbers =\",\r\n maxnum)\r\n<\/pre>\n
The largest number among the three numbers = 7<\/pre>\n
\n