asked 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.

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

answered
User Memmons
by
8.1k points

No related questions found