Calculate the number of upper case letters and lower case letter in Python


Write a Python function that accepts a string and calculate the number of upper case letters and lower case letter in Python 


def Letter(s):
    c1,c2=0,0
    for i in s:
        if i.isupper():
            c1+=1
        elif i.islower():
            c2+=1
    print("Upper Case Letters:-",c1)
    print("Lower Case Letters:-",c2)
s=input("Enter Something:--")
Letter(s)   
Output:

Enter Something:--cwipedia.in
Upper Case Letters:- 0
Lower Case Letters:- 10


Explanation:

isupper() is a built-in function in python, it is used to check string is upper case letter or not.

islower() is also a built-in function in python, used to checked lower letters


Firstly the program asked for "Enter something" when we entered string(cwipedia.in), it will saved in variable s, then we have called letter() function and passes the variable s containing value cwipedia.in

Now within the function, there are two variables c1,c2 for counting cases of the letter, if the string containing upper case letter then c1 will be incremented by 1 and so on, similarly, elif block do the same thing for lower case letter, And the for loop is used for checking every letter into a string 

Comments