164k views
3 votes
Create a function that returns a dictionary containing the number of upper and lower case characters in a string (e.g. {'lower': 8, 'upper': 2}). Ignore whitespace characters. Your function should be able to handle an empty string, though.

1 Answer

3 votes

Answer:

Step-by-step explanation:

The following is written in Python and takes in the input string, then loops through it counting all of the upper and lower case letters and adds it to the dictionary.

string = input("input string: ")

upper_case = 0

lower_case = 0

for char in string:

if char.isupper() == True:

upper_case += 1

elif char == ' ':

pass

else:

lower_case += 1

letter_dict = {'upper_case': upper_case, 'lower_case': lower_case}

Create a function that returns a dictionary containing the number of upper and lower-example-1
User SPatil
by
4.4k points