{"id":8628,"date":"2021-09-30T11:00:53","date_gmt":"2021-09-30T05:30:53","guid":{"rendered":"https:\/\/python-programs.com\/?p=8628"},"modified":"2021-11-22T18:35:30","modified_gmt":"2021-11-22T13:05:30","slug":"python-program-to-print-largest-even-and-largest-odd-number-in-a-list","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-print-largest-even-and-largest-odd-number-in-a-list\/","title":{"rendered":"Python Program to Print Largest Even and Largest Odd Number in a List"},"content":{"rendered":"
Want to excel in java coding? Practice with these Java Programs examples with output<\/a> and write any kind of easy or difficult programs in the java language<\/p>\n List in Python :<\/strong><\/p>\n The list data type is one of the most often used data types in Python. The square brackets [ ] easily identify a Python List. Lists are used to store data items, with each item separated by a comma (,). A Python List can include data elements of any data type, including integers and Booleans.<\/p>\n One of the primary reasons that lists are so popular is that they are mutable. Any data item in a List can be replaced by any other data item if it is mutable. This distinguishes Lists from Tuples, which are likewise used to store data elements but are immutable.<\/p>\n Given a list, the task is to print the largest Even and Largest Odd number in the given list in Python<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to print the largest even element and largest odd element in the given list :<\/p>\n Drive into Python Programming Examples<\/a> and explore more instances related to python concepts so that you can become proficient in generating programs in Python Programming Language.<\/p>\n Approach:<\/strong><\/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 Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Want to excel in java coding? Practice with these Java Programs examples with output and write any kind of easy or difficult programs in the java language List in Python : The list data type is one of the most often used data types in Python. The square brackets [ ] easily identify a Python …<\/p>\ngiven list =[12, 21, 45, 146, 197, 4]<\/pre>\n
The Largest even number in the given list [12, 21, 45, 146, 197, 4] = 146\r\nThe Largest odd number in the given list [12, 21, 45, 146, 197, 4] = 197<\/pre>\n
given list = [532, 234, 9273, 845, 1023, 9]<\/pre>\n
The Largest even number in the given list [532, 234, 9273, 845, 1023, 9] = 532\r\nThe Largest odd number in the given list [532, 234, 9273, 845, 1023, 9] = 9273<\/pre>\n
Program to Print Largest Even and Largest Odd Number in a List in Python<\/h2>\n
\n
Method #1: Using sort() and Conditional Statements(User Input)<\/h3>\n
\n
# scanning the total number of elements of the given list\r\ntotalCount = int(\r\n input(\"Enter the total number of elements of the given list = \"))\r\n# Taking a empty list\r\ngiven_list = []\r\n# Using for loop to loop totalCount times\r\nfor i in range(totalCount):\r\n eleme = int(input(\"Enter some random element(integer) = \"))\r\n given_list.append(eleme)\r\n# Taking two empty lists which stores eeven and odd numbers\r\nevenNumList = []\r\noddNumList = []\r\n# Traversing the list using for loop\r\nfor eleme in given_list:\r\n # if the element is even then add this element to evenNumList using append() function\r\n if(eleme % 2 == 0):\r\n evenNumList.append(eleme)\r\n # if the element is even then add this element to oddNumList using append() function\r\n else:\r\n oddNumList.append(eleme)\r\n# sorting evenNumList using sort() function\r\nevenNumList.sort()\r\n# sorting oddNumList using sort() function\r\noddNumList.sort()\r\nprint(\"The Largest even number in the given list\",\r\n given_list, \"=\", evenNumList[-1])\r\nprint(\"The Largest odd number in the given list\",\r\n given_list, \"=\", oddNumList[-1])\r\n<\/pre>\n
Enter the total number of elements of the given list = 6\r\nEnter some random element(integer) = 12\r\nEnter some random element(integer) = 21\r\nEnter some random element(integer) = 45\r\nEnter some random element(integer) = 146\r\nEnter some random element(integer) = 197\r\nEnter some random element(integer) = 4\r\nThe Largest even number in the given list [12, 21, 45, 146, 197, 4] = 146\r\nThe Largest odd number in the given list [12, 21, 45, 146, 197, 4] = 197<\/pre>\n
Method #2: Using sort() and Conditional Statements(Static Input)<\/h3>\n
\n
# given list\r\ngiven_list = [532, 234, 9273, 845, 1023, 9]\r\n# Taking two empty lists which stores eeven and odd numbers\r\nevenNumList = []\r\noddNumList = []\r\n# Traversing the list using for loop\r\nfor eleme in given_list:\r\n # if the element is even then add this element to evenNumList using append() function\r\n if(eleme % 2 == 0):\r\n evenNumList.append(eleme)\r\n # if the element is even then add this element to oddNumList using append() function\r\n else:\r\n oddNumList.append(eleme)\r\n# sorting evenNumList using sort() function\r\nevenNumList.sort()\r\n# sorting oddNumList using sort() function\r\noddNumList.sort()\r\nprint(\"The Largest even number in the given list\",\r\n given_list, \"=\", evenNumList[-1])\r\nprint(\"The Largest odd number in the given list\",\r\n given_list, \"=\", oddNumList[-1])\r\n<\/pre>\n
The Largest even number in the given list [532, 234, 9273, 845, 1023, 9] = 532\r\nThe Largest odd number in the given list [532, 234, 9273, 845, 1023, 9] = 9273<\/pre>\n
Method #3:Using sort and List Comprehension(Static Input)<\/h3>\n
\n
# given list\r\ngiven_list = [532, 234, 9273, 845, 1023, 9]\r\n# Take all even numbers and odd numbers of the given list into\r\n# two separate lists using List Comprehension\r\nevenNumList = [eleme for eleme in given_list if eleme % 2 == 0]\r\noddNumList = [eleme for eleme in given_list if eleme % 2 != 0]\r\n# sorting evenNumList using sort() function\r\nevenNumList.sort()\r\n# sorting oddNumList using sort() function\r\noddNumList.sort()\r\nprint(\"The Largest even number in the given list\",\r\n given_list, \"=\", evenNumList[-1])\r\nprint(\"The Largest odd number in the given list\",\r\n given_list, \"=\", oddNumList[-1])\r\n<\/pre>\n
Method #4:Using sort and List Comprehension(User Input)<\/h3>\n
\n
# scanning the total number of elements of the given list\r\ntotalCount = int(\r\n input(\"Enter the total number of elements of the given list = \"))\r\n# Taking a empty list\r\ngiven_list = []\r\n# Using for loop to loop totalCount times\r\nfor i in range(totalCount):\r\n eleme = int(input(\"Enter some random element(integer) = \"))\r\n given_list.append(eleme)\r\n# Take all even numbers and odd numbers of the given list into\r\n# two separate lists using List Comprehension\r\nevenNumList = [eleme for eleme in given_list if eleme % 2 == 0]\r\noddNumList = [eleme for eleme in given_list if eleme % 2 != 0]\r\n# sorting evenNumList using sort() function\r\nevenNumList.sort()\r\n# sorting oddNumList using sort() function\r\noddNumList.sort()\r\nprint(\"The Largest even number in the given list\",\r\n given_list, \"=\", evenNumList[-1])\r\nprint(\"The Largest odd number in the given list\",\r\n given_list, \"=\", oddNumList[-1])\r\n<\/pre>\n
Enter the total number of elements of the given list = 5\r\nEnter some random element(integer) = 234\r\nEnter some random element(integer) = 122\r\nEnter some random element(integer) = 65\r\nEnter some random element(integer) = 19\r\nEnter some random element(integer) = 102\r\nThe Largest even number in the given list [234, 122, 65, 19, 102] = 234\r\nThe Largest odd number in the given list [234, 122, 65, 19, 102] = 65<\/pre>\n
\n