31 - Write a program in Python to input a string, then Count and display the number of vowels, consonants, uppercase, lowercase characters in string.
S=input("Enter a string: ")
v=0
c=0
u=0
l=0
print("Total number of characters in the string = ", len(S))
for i in S:
if i in 'aeiouAEIOU':
v=v+1
elif i>='a' and i<='z':
c=c+1
elif i>='A' and i<='Z':
c=c+1
print("Number of Vowels = ", v)
print("Number of consonants = ", c)
for i in S:
if i.isupper():
u=u+1
elif i.islower():
l=l+1
print("Number of uppercase letters = ", u)
print("Number of lowercase letters = ", l)
Output:
Enter a string: This is a Python Program
Total number of characters in the string = 24
Number of Vowels = 6
Number of consonants = 14
Number of uppercase letters = 3
Number of lowercase letters = 17
Enter a string: S@chin P@r@sh@r
Total number of characters in the string = 15
Number of Vowels = 1
Number of consonants = 9
Number of uppercase letters = 2
Number of lowercase letters = 8
No comments:
Post a Comment