Advertisement
singam_dev57

Count Uppercase and Lowercase Letters in String

Dec 27th, 2024 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | Source Code | 0 0
  1. def uppercase_lowercase_count(text = "This Sentence Has Mixed CASE Letters!"):
  2.     uppercase_count = 0
  3.     lowercase_count = 0
  4.  
  5.     for char in text:
  6.         if char.isalpha() and char.isupper():    # Check for upper characters and alphabetic characters only
  7.             uppercase_count = uppercase_count + 1
  8.         elif char.isalpha() and char.islower():  # Check for upper characters and alphabetic characters only
  9.             lowercase_count = lowercase_count + 1
  10.  
  11.     return uppercase_count, lowercase_count
  12.  
  13. # Function call and result display
  14. uppercase_count, lowercase_count = uppercase_lowercase_count()
  15.  
  16. print(f"The number of uppercase letter is: {uppercase_count}")
  17. print(f"The number of lowercase letter is: {lowercase_count}")
  18.  
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement