0 out of 464 challenges solved

Count Element in Tuple

Write a Python function `count_occurrences(tup, element)` that takes in a tuple `tup` and an element `element`, and returns the number of times `element` appears in `tup`.

#### Example Usage
```python [main.nopy]
print(count_occurrences((1, 2, 3, 2, 4, 2), 2))  # Output: 3
print(count_occurrences(("a", "b", "a", "c"), "a"))  # Output: 2
print(count_occurrences((5, 6, 7), 8))  # Output: 0
```

#### Constraints
- The input `tup` will always be a tuple.
- The function should handle tuples containing any type of elements.
- The function should return `0` if the element is not found in the tuple.
def count_occurrences(tup, element):
    """
    Count the occurrences of an element in a tuple.

    Parameters:
    tup (tuple): The tuple to search within.
    element (any): The element to count.

    Returns:
    int: The number of times the element appears in the tuple.
    """
    # Initialize a counter
    count = 0
    # Iterate through the tuple and count occurrences
    # Placeholder for solution
    return count