In this python tuple program, we will find the maximum value from a tuple.
Steps to solve the program
- Create a tuple.
- Find the maximum value from a tuple using max().
- Print the output.
tup = (41, 15, 69, 55)
print("Maximum value: ",max(tup))
Output :
Maximum value: 69
Solution2 :
# take input tuple with multiple values
tup = (41, 15, 69, 101, 55)
# initiate a variable to store max value
max_val = 0
# interate through tuple values using loop
for val in tup:
# check if val is greater than max_val
if val > max_val:
# assign variable value to max_val.
max_val = val
else:
continue
print("maximum value :", max_val)
Output :
maximum value : 101
1 thought on “Find the maximum value from a tuple”