Python Exercise 14 Problem
In this Python exercise, write a Python program to calculate the number of uppercase letters and lowercase letters from user input and print the results.. There are functions called isupper() and islower() that may be of help in this exercise.
For example, if a user entered the word, HeLlO. This input should provide an output of 3 uppercase letters and 2 lowercase letters.
Solution Python Exercise 14
Python Code Input:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | print("Enter a random sentence: ") sentence = input() uppercase_lowercase = {"Upper":0, "Lower":0} for x in sentence: if x.isupper(): uppercase_lowercase["Upper"]+=1 elif x.islower(): uppercase_lowercase["Lower"]+=1 else: pass print("Upper", uppercase_lowercase["Upper"]) print("Lower", uppercase_lowercase["Lower"]) |
User Input:
1 2 | Enter a random sentence: I hope this Python ExErCiSe is fun! |
Python Code Output:
1 2 | Upper 6 Lower 22 |