Exercise 64

Write a Python program as function which takes a string ‘s’ as parameter and return the number of Uppercase characters within the string ‘s’. Example: if s = “Python Programming”, the function must returns 2.


def count_uppercase(s):
    # We initialize a counter variable count to 0
    count = 0

    # and then loop through each character in the string s
    for char in s:

        # we test if the character is uppercase 
        # and the we increment the count variable by 1
        if char.isupper():
            count += 1
    return count

s = "Python Programming"
print(count_uppercase(s)) # Output: 2


Younes Derfoufi

One thought on “Solution Exercise 64: python function which compute the number of uppercase character within a given string s”

Leave a Reply