top of page
Writer's pictureRajesh Singh

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

Updated: Feb 19, 2023

Write a python program that takes a sentence as input and displays the number of words,number of capital letter, number of small letter and number of special symbols in the inputted sentence.

This program is most for O Level Practical. So read it carefully.

Program:

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



744 views0 comments

Recent Posts

See All

Comments


bottom of page