0
7.4kviews
Write a Python function that accepts a string and calculate the number of upper case letters and lower case letters
1 Answer
0
1.5kviews

Explanation:-

  • Take a string as a input form the user and pass the string to function char.
  • Initialize 2 variable l and u to 0.
  • Iterate over the characters of the string check of the entered string is in lower or upper case accordingly increment the values or the l and u.
  • print the l & u.

Code:-

x=input("Enter the string:- ")
def char(x):
  u=0
  l=0
  for i in x:
      if i>='a' and i<='z':
       l+=1

      if i >='A' and i<='Z':
       u+=1

  print("LowerCase letter in the String",l)
  print("UpperCase letter in the String",u)
char(x)

Output:-

enter image description here

enter image description here

Please log in to add an answer.