Count Upper Case and Lower Case Word in a string (Python)

 
Count Upper Case and Lower Case Word in a string     (Python)

def string_test(s):

    d={"UPPER_CASE":0, "LOWER_CASE":0}

    for c in s:

        if c.isupper():

           d["UPPER_CASE"]+=1

        elif c.islower():

           d["LOWER_CASE"]+=1

        else:

           pass

    print ("Original String : ", s)

    print ("No. of Upper case characters : ", d["UPPER_CASE"])

    print ("No. of Lower case Characters : ", d["LOWER_CASE"])


string_test('My Name is Gurpinder Singh')


Output :

Original String :  My Name is Gurpinder Singh

No. of Upper case characters :  4

No. of Lower case Characters :  18



0 comments:

Post a Comment

gurnoorsingh5974@gmail.com

Count Upper Case and Lower Case Word in a string (Python)

  Count Upper Case and Lower Case Word in a string     (Python) def string_test(s):     d={"UPPER_CASE":0, "LOWER_CASE":...