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
Post a Comment