CBSE Class 11 Computer Science Question 112 of 114

Tuples — Question 15

Back to all questions
15
Question

Question 13

Write a program to check the mode of a tuple is actually an element with maximum occurrences.

Solution
tup = eval(input("Enter a tuple: "))
maxCount = 0
mode = 0

for i in tup :
      count = tup.count(i)
      if maxCount <  count:
            maxCount = count
            mode = i

print("mode:", mode)
Output
Enter a tuple: 2,4,5,2,5,2
mode =  2
Answer