Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Daily Python Projects
- Count Uppercase and Lowercase Letters in String
- Level 1: Beginner
- https://dailypythonprojects.substack.com/p/count-uppercase-and-lowercase-letters
- This program defines a string, counts how many uppercase and lowercase letters are present, and displays both counts.
- """
- text = "This Sentence Has Mixed CASE Letters!"
- count_upper = 0
- count_lower = 0
- for letter in text:
- if letter.isupper():
- count_upper += 1
- elif letter.islower():
- count_lower += 1
- print (f"The text contain {count_upper} uppercase and {count_lower} lowercase letters.")
Advertisement
Comments
-
- Improved code:
- text = "This Sentence Has Mixed CASE Letters!"
- count_upper = sum([1 for character in text if character.isupper()])
- count_lower = sum([1 for character in text if character.islower()])
- print (f"The text contain {count_upper} uppercase and {count_lower} lowercase letters.")
Add Comment
Please, Sign In to add comment
Advertisement