Python Exercise: Repeated items of a tuple
Write a Python program to find repeated items in a tuple.
Visual Presentation:
Sample Solution:
Python Code:
# Create a tuple containing a sequence of numbers
tuplex = 2, 4, 5, 6, 2, 3, 4, 4, 7
# Print the contents of the 'tuplex' tuple
print(tuplex)
# Count the number of times the value 4 appears in the 'tuplex' tuple
count = tuplex.count(4)
# Print the count of how many times 4 appears
print(count)
Sample Output:
(2, 4, 5, 6, 2, 3, 4, 4, 7) 3
Flowchart:
Python Code Editor:
Previous: Write a Python program to create the colon of a tuple.
Next: Write a Python program to check whether an element exists within a tuple.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics