Write a Python program to count all lower case, upper case, digits, and special symbols from a given string
In this article, we will write a Python program to count all lower case, upper case, digits, and special symbols from a given string.
Write a Python program to count all lower case, upper case, digits, and special symbols from a given string
def counter(strr):
lowerCaseCounter = 0
upperCaseCounter = 0
numberCounter = 0
specialCounter = 0
for letter in strr:
if letter.islower():
lowerCaseCounter = lowerCaseCounter + 1
elif letter.isupper():
upperCaseCounter = upperCaseCounter + 1
elif letter.isnumeric():
numberCounter = numberCounter + 1
else:
specialCounter = specialCounter + 1
print("Number of lowercase characters:" + str(lowerCaseCounter))
print("Number of uppercase characters:"+str(upperCaseCounter))
print("Number of number characters:"+str(numberCounter))
print("Number of special characters:" + str(specialCounter))
return
counter("source code examples SOURCE 12345 @#$%^&*()_+")
Output:
Number of lowercase characters:18
Number of uppercase characters:6
Number of number characters:5
Number of special characters:16
Comments
Post a Comment