0 out of 464 challenges solved

Count Digits in String

Write a Python function `count_digits` that takes a single string as input and returns the number of digit characters (`0-9`) present in the string.

#### Example Usage
```python [main.nopy]
print(count_digits("hello123"))  # Output: 3
print(count_digits("abc"))       # Output: 0
print(count_digits("2023!"))    # Output: 4
```
def count_digits(input_string):
    """
    Count the number of digit characters in the given string.

    Args:
        input_string (str): The string to analyze.

    Returns:
        int: The count of digit characters in the string.
    """
    # Initialize a counter for digits
    digit_count = 0
    # Iterate through each character in the string
    for char in input_string:
        # Check if the character is a digit
        if char.isdigit():
            # Increment the counter
            digit_count += 1
    # Return the total count of digits
    return digit_count