Python program that accepts a sentence and calculate the number of different type of characters .

 

str = input ('Enter string')

len = len (str)

print ('Length of str = ',len)

cu,cc,cd,cs,csd=0,0,0,0,0

for j in range (len):

    i=str[j]

    if (ord(i)>=65 and ord (i)<=90):

        cu+=1

    elif (ord(i)>=97 and ord (i)<=122):

        cl+=1

    elif (i==' '):

        cs+=1

    elif (ord(i)>=48 and ord (i)<=57):

        cd+=1

    else :

        csd+=1


print ('Upper Case Letters = ', cu)

print ('Lower Case Letters = ', cl)

print ('Letters = ', cl+cu)

print ('Digits = ', cd)

print ('Space = ', cs)

print ('Special Digits = ', csd)

print ('Total length = ', cv+cc+cd+cs+csd)

Comments

Some popular posts

Python Program that computes the net amount of a bank account based a transaction log from console input.

Python Program which will find all such numbers between 1000 and 3000 (both included) such that each digit of the number is an even number.The numbers obtained should be printed in a comma-separated sequence on a single line