Advertisement
Edwinlga

count_uppercase_lowercase.py

Feb 8th, 2025
24
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | Source Code | 0 0
  1. """
  2. Daily Python Projects
  3. Count Uppercase and Lowercase Letters in String
  4. Level 1: Beginner
  5. https://dailypythonprojects.substack.com/p/count-uppercase-and-lowercase-letters
  6.  
  7. This program defines a string, counts how many uppercase and lowercase letters are present, and displays both counts.
  8. """
  9. text = "This Sentence Has Mixed CASE Letters!"
  10. count_upper = 0
  11. count_lower = 0
  12.  
  13. for letter in text:
  14.     if letter.isupper():
  15.         count_upper += 1
  16.     elif letter.islower():
  17.         count_lower += 1
  18.  
  19. print (f"The text contain {count_upper} uppercase and {count_lower} lowercase letters.")
Tags: python
Advertisement
Comments
  • Edwinlga
    129 days
    # Python 0.29 KB | 0 0
    1. Improved code:
    2.  
    3. text = "This Sentence Has Mixed CASE Letters!"
    4. count_upper = sum([1 for character in text if character.isupper()])
    5. count_lower = sum([1 for character in text if character.islower()])
    6.  
    7. print (f"The text contain {count_upper} uppercase and {count_lower} lowercase letters.")
Add Comment
Please, Sign In to add comment
Advertisement