Python program count the number of alphabets, lowercase letters, uppercase letters, digits and words

write a function that reads the contents of the String and counts the number of alphabets, lowercase letters, uppercase letters, digits and no of words.


def count(str):

alpha, uppercase, lowercase, digit,words=0,0,0,0,0

for i in range (len(str)):

if str[i]>='A'and str[i]<='Z':

uppercase=uppercase+1

alpha=alpha+1

elif str[i]>='a' and str[i]<='z':

lowercase=lowercase+1

alpha=alpha+1

elif str[i]>='0' and str[i]<='9':

digit=digit+1

elif str[i]==' ':

words=words+1

print("Total characters:", len(str))

print("Total Alphabets : ", alpha)

print("Upper Case letters:", uppercase)

print("Lower case letters:", lowercase)

print("Total digits:", digit)

print("Total words:", words+1)

str="Career Bodh Shikshan Prashikshan Sansthan 2013"

count(str)

Output:

Total characters: 46

Total Alphabets : 37

Upper Case letters: 5

Lower case letters: 32

Total digits: 4

Total words: 6



78 views0 comments

Recent Posts

See All