Home » Python program that reads a line and prints its statistics like:

Python program that reads a line and prints its statistics like:

Number of uppercase letters

Number of lowercase letters

Number of alphabets

Number of digits

Number of symbols

line=input("Enter a line:")
lower_count=upper_count=0
digit_count=alpha_count=sym_count=0
for a in line:
    if a.islower():
        lower_count+=1
    elif a.isupper():
        upper_count+=1
    elif a.isdigit():
        digit_count+=1
    elif a.isalpha():
        alpha_count+=1
    elif a.isalnum()!=True and a!=' ':
        sym_count+=1
print("Number of uppercase letters:", upper_count)
print("Number of lowercase letters:", lower_count)
print("Number of alphabets:", alpha_count)
print("Number of digits:", digit_count)
print("Number of symbols:", sym_count)

Contents

Output

Enter a line:Learning computer is Fun!!

Number of uppercase letters: 2

Number of lowercase letters: 19

Number of alphabets: 0

Number of digits: 0

Number of symbols: 2