Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help with python assignment Part V: Count Uppercase and Lowercase Letters (

ID: 3822831 • Letter: N

Question

need help with python assignment

Part V: Count Uppercase and Lowercase Letters (2 points) Write a recursive function count-upper-lower that takes a non-empty string as its argument and returns a tuple containing the counts of how many letters in the string are uppercase and how many are lowercase (in that order). To solve this problem you will need to write a function that returns a pair of values (i.e., a tuple). For example, suppose we wanted to write a function that returned the sum and product of two values passed as arguments to the function. We might write this code

Explanation / Answer

counterupper = 0
counterlower = 0
def count_upper_lower(string = None):
global counterupper,counterlower
if(len(string) == 0):
counteruppercopy = counterupper
counterlowercopy = counterlower
counterupper = 0
counterlower = 0
return (counteruppercopy,counterlowercopy)
if(string[0].isupper() == True):
counterupper = counterupper + 1
if(string[0].islower() == True):
counterlower = counterlower + 1
return count_upper_lower(string[1:])