Write a recursive function named get_first_capital(word) that takes a string as a parameter and returns the first capital letter that exists in a string using recursion. This function has to be recursive; you are not allowed to use loops to solve this problem.
Test: Except: print(get_first_capital('helLo')) L
s = 'great' print(get_first_capital(s)) None
And
Write a recursive function named count_uppercase(my_string) that finds the number of uppercase letters in the parameter string. Note: This function has to be recursive; you are not allowed to use loops to solve this problem!
You may want to use a helper function to do the counting. The helper function header is:
def count_uppercase_helper(a_string, index):
Test: Except:
print(count_uppercase('This is a Test')) 2
def get_first_capital(word): if(len(word)==0): return None else: if(word[0].isupper()): return word[0] else: return get_first_capital(word[1:]) # Testing print(get_first_capital('helLo')) s = 'great' print(get_first_capital(s))
======================================
def count_uppercase(my_string): if (len(my_string) == 0): return 0 else: if (my_string[0].isupper()): return 1 + count_uppercase(my_string[1:]) else: return count_uppercase(my_string[1:]) # Testing print(count_uppercase('This is a Test'))
Get Answers For Free
Most questions answered within 1 hours.