Thursday, 15 February 2024

Class 11 CS Practical - 51

 

51 - Write a program in Python to count the frequency of all elements of a tuple


T= (10, 20, 30, 20, 40, 30, 20, 50)

print("Tuple is: ",T)

Uni= ()

for i in T:

    if i not in Uni:

        Uni = Uni + (i,)

for i in Uni:

    print(i,":",T.count(i))


Output:

Tuple is:  (10, 20, 30, 20, 40, 30, 20, 50)

10 : 1

20 : 3

30 : 2

40 : 1

50 : 1

No comments:

Post a Comment