Computer Science, asked by xasin38520, 7 months ago

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 jai696
9

\large\mathsf\color{pink}{Solution\: using\: python\: 3}

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))

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Similar questions