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)
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)
Comments
Leave a comment