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

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



635 views0 comments

Recent Posts

See All

Python program to calculate the factorial of a number

Write a Python function to calculate the factorial of a number (a non-negative integer). The function accepts the number as an argument. This program is most for O Level Practical Exam so read it care

NumPy program to find the most frequent value in the list.

This program is most for O Level Practical Exam so read it carefully. Program: import numpy as np x = np.array([1,2,3,4,5,7,2,1,1,1,8,9,1]) print(x) print("most frequent value in the list:") print(np.

bottom of page