0 out of 464 challenges solved
Write a Python function `count_uppercase` that takes a string as input and returns the number of uppercase characters in the string. #### Example Usage ```python [main.nopy] print(count_uppercase("Hello World")) # Output: 2 print(count_uppercase("python")) # Output: 0 print(count_uppercase("PYTHON")) # Output: 6 ```
def count_uppercase(s: str) -> int: """ Count the number of uppercase characters in the given string. Args: s (str): The input string. Returns: int: The count of uppercase characters. """ # Initialize a counter for uppercase characters count = 0 # Iterate through each character in the string for char in s: # Check if the character is uppercase if char.isupper(): # Increment the counter count += 1 # Return the final count return count