Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want recursive function for count_upper_lower(word) . This is my code. How can I fix it so it is recursive ? def count_upper_lower(word): lowerCount =

image text in transcribedimage text in transcribed

I want recursive function for count_upper_lower(word). This is my code. How can I fix it so it is recursive?

def count_upper_lower(word): lowerCount = 0 upperCount = 0 for i in range(len(word)): if word[i] >= 'a' and word[i] 'z': lowerCount = lowerCount + 1 elif word[i] >= 'A' and word[i] 'Z': upperCount = upperCount + 1 return upperCount, lowerCount 
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: def sum prod (a, b) return a+b, a b Here is an example of how we might call the function and access the return values. s, p sum prod (3 6) print (s, p) In this example, the two return values will be assigned to s and p accordingly based on their position in the tuple. In other words, atb will be assigned to s and a b will be assigned to p Here is some pseudocode you can consider implementing if you get stuck: IF the word has only 1 character (BASE CASE) 1. return a pair of integers to indicate whether that character is an uppercase letter lower case letter, or neither (for example, the tuple (1,0) would indicate an uppercase letter) OTHERWISE, the word has more than one character (RECURSIVE STEP) 1. determine if the first character is an uppercase letter lowercase letter, or neither (name this tuple (upper, lower) 2. recursively count the number of uppercase and lowercase letters in

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions