339,437 views
13 votes
13 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.

User Pjivers
by
2.8k points

1 Answer

22 votes
22 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 Atamata
by
2.6k points