Answer to Question #157390 in Python for Andu

Question #157390

2. Write a python function called upperLower that takes a string as an argument and returns: the number of uppercase letters, the number of lowercase letters and the positive difference between those two.

Sample:

Argument: ThiS iS A SamPle sentENCE.

The function will return: (9, 12, 3)

Explanation of result: There are 9 Upper case letters, 12 Lower case letters and the positive difference is 3. (Hint: Use string built-in functions isupper) and islower0 to check if a letter is uppercase or lowercase)


1
Expert's answer
2021-01-23T10:19:14-0500
def upperLower(s):
    count_up, count_low = 0, 0
    for x in s:
        if x.isupper():
            count_up += 1
        else:
            count_low += 1
    return count_up, count_low, abs(count_up - count_low)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS