By iterating over the string character by character, we can count number of upper case characters in a string.
count_uppercase_chars.py
def count_uppercase_characters(input_str):
count = 0
for ch in input_str:
if ch.isupper():
count += 1
return count
input = 'Hello WorlD'
print('Number of uppercase characters in "',input,'" is ', count_uppercase_characters(input))
Output
Number of uppercase characters in " Hello WorlD " is 3
No comments:
Post a Comment