170k views
15 votes
Write a function named count_case that takes a string as an argument and returns the count of upper case and lower case characters in the string (in that order). Any characters that are not letters should be ignored.

User Metabolic
by
3.9k points

1 Answer

6 votes

Answer:

def count_case(input): #create a function

uppercase = 0 #declare variables

lowercase = 0

for x in input: #loop through user input looking at each letter

if x.isupper(): #if letter is uppercase

uppercase += 1 #increment the uppercase counter

elif x.islower(): #otherwise if it is lowercase

lowercase += 1 #increment the lowercase counter

print(uppercase) #print uppercase count

print(lowercase) #print lowercase count

string = input("enter string: ") #ask for user input

count_case(string) #run function

User Memmons
by
3.4k points