KnowledgeBoat Logo

Computer Science

Write a program to check if the smallest element of a tuple is present at the middle position of the tuple.

Python

Python Tuples

1 Like

Answer

tup = (5, 9, 1, 8, 7)
smallest = min(tup)
middle_index = len(tup) // 2
if tup[middle_index] == smallest:
    print("The smallest element is at the middle position.")
else:
    print("The smallest element is NOT at the middle position.")

Output

The smallest element is at the middle position.

Answered By

2 Likes


Related Questions