Python Program to Find Largest Item in a Tuple
Given a tuple, the task is to write a Python program to find the greatest number in a Tuple.
Example:
Input: (10,20,23,5,2,90) #tuple Output: 90
Values of a tuple are syntactically separated by ‘commas’. Although it is not necessary, it is more common to define a tuple by closing the sequence of values in parentheses. This helps in understanding the Python tuples more easily.
Python program to demonstrate the maximum element in a Tuple.
Method 1: Using the max() method
We can use Python built-in max() Method to find the maximum element in a tuple.
Python3
|
Output:
Enter number separated by comma: 10,20,23,5,2,80 Greatest number in the tuple is: 80
Method 2: Using for-loop
Here we iterate on the for-loop and compare each element to find the maximum element in the tuple.
Python3
|
Output:
Maximum value is: 63
Method 3: Using Recursive Functions
Here, we have used a recursive function to find the maximum element in the tuple.
Python3
|
Output:
Tuple Items = (11, 65, 54, 23, 76, 33, 82, 98)
Maximum Item in Tuple = 98
Given a tuple, the task is to write a Python program to find the greatest number in a Tuple.
Example:
Input: (10,20,23,5,2,90) #tuple Output: 90
Values of a tuple are syntactically separated by ‘commas’. Although it is not necessary, it is more common to define a tuple by closing the sequence of values in parentheses. This helps in understanding the Python tuples more easily.
Python program to demonstrate the maximum element in a Tuple.
Method 1: Using the max() method
We can use Python built-in max() Method to find the maximum element in a tuple.
Python3
|
Output:
Enter number separated by comma: 10,20,23,5,2,80 Greatest number in the tuple is: 80
Method 2: Using for-loop
Here we iterate on the for-loop and compare each element to find the maximum element in the tuple.
Python3
|
Output:
Maximum value is: 63
Method 3: Using Recursive Functions
Here, we have used a recursive function to find the maximum element in the tuple.
Python3
|
Output:
Tuple Items = (11, 65, 54, 23, 76, 33, 82, 98)
Maximum Item in Tuple = 98