write a program in Python alphabet digit space and special term
Answers
I am assuming that we need to write a python code to count the number of alphabets, digits, spaces and special terms.
To check for alphabet, we cause use .isalpha()
To check for digits, we can use .isdigit()
To check for spaces, we can use == ' '
To check for special characters, we can see whether it is one of these:
[@_!#$%^&*()<>?/\|}{~:]
___________________________________________
CODE 1:
alphabets,numbers,spaces,spe = 0,0,0,0
special = '[@_!#$%^&*()<>?/\|}{~:]'
string = input('Enter your string:')
for letter in string:
if letter.isalpha():
alphabets += 1
elif letter.isdigit():
numbers += 1
elif letter == ' ':
spaces += 1
elif letter in special:
spe += 1
print(f'Alphabets:{alphabets}\nNumbers:{numbers}\nSpaces:{spaces}\nSpecial characters:{spe}')