![Python-courses-python-exercises-python-for-while](https://1.bp.blogspot.com/-T3BongcoJFo/X4CftQxVL8I/AAAAAAAAB5U/Lf59WgNyhGo2FdogKqxv0PIy_Ef7XDPdgCLcBGAsYHQ/s0/my-python-courses-python-exercises-with-solutions.png)
Exercise 64
Write a Python program to count the Uppercase characters within a given string. Example if s = "Python Programming", the program must returns 2.
Solution
def countUpper(s):
# initializing the number of uppercase characters
numberUpper = 0
# iterate over all characters of s:
for x in s:
if x.isupper():
numberUpper = numberUpper + 1
return numberUpper
#Testing algorithm:
s = "Python Programmin"
print("The number of uppercase characters in s is :" , countUpper(s))
# The output is :
# The number of uppercase characters in s is : 2
Younes Derfoufi
my-courses.net
my-courses.net