Write a python program to count the number of alphabets, numbers and special characters in a given string.
Eg: For the string ‘Happiest year 2019 is @ ending’ the output will be
20 4 6
Answers
Answered by
4
Answer:
This python program allows the user to enter a string.
First, we used For Loop to iterate characters in a String. Inside the For Loop, we are using Elif Statement
isalpha() in the first statement is to check whether the character is an alphabet or
not. If true, alphabets value incremented.
isdigit() in the second statement checks
whether the character is Digit or not. If true, digits value incremented.
Otherwise, special characters value incremented.
# Python program to Count Alphabets Digits and Special Characters in a String
string = input("Please Enter your Own String : ")
alphabets = digits = special = 0
for i in range(len(string)):
if(string[i].isalpha()):
alphabets = alphabets + 1
elif(string[i].isdigit()):
digits = digits + 1
else:
special = special + 1
Explanation:
hope it's helpful for uh
plz add me brainlist
Similar questions