Q11. WAP to accept a line from the user and count by alphabet's, numbers, space and special characters in python programming
Answers
Answered by
9
def character_counter(string):
alphabets = 0
numbers = 0
spaces = 0
special_chars = 0
for x in string:
if not x.isalpha() and not x.isdigit() and not x.isspace():
special_chars += 1
if x.isalpha():
alphabets += 1
if x.isdigit():
numbers += 1
if x.isspace():
spaces += 1
return f"alphabets: {alphabets}\nnumbers: {numbers}\nspaces: {spaces}\nspecial_chars: {special_chars}"
line = input("enter a line: ")
print(character_counter(line))
Similar questions