In this program, we will take a string as input and count all the Uppercase, Lowercase, special character and numeric values in a given string.
Steps to solve the program
- Take a string as input.
- Create some variables and assign their values equal to 0.
- Use for loop to iterate over each character of the string.
- Check the type of the character and add 1 to the respective variable.
- Print the output.
#Input string
str1 = "@SqaTools#lin"
upper = 0
lower = 0
digit = 0
symbol = 0
for val in str1:
if val.isupper():
upper += 1
elif val.islower():
lower += 1
elif val.isdigit():
digit += 1
else:
symbol += 1
#Printing output
print("Uppercase: ", upper)
print("Lowercase: ", lower)
print("Digits: ", digit)
print("Special characters: ", symbol)
Output :
Uppercase: 2
Lowercase: 9
Digits: 0
Special characters: 2