Skip to content

Write a python program to Count Vowels, Consonants, Digits and Spaces

Class 11th IP (065)

Write a python program to Count Vowels, Consonants, Digits and Spaces

SOLUTION..

while True: s = input("\nEnter a string: ") vowels = consonants = digits = spaces = 0 for ch in s: if ch.isalpha(): if ch.lower() in "aeiou": vowels += 1 else: consonants += 1 elif ch.isdigit(): digits += 1 elif ch.isspace(): spaces += 1 print("Vowels =", vowels) print("Consonants =", consonants) print("Digits =", digits) print("Spaces =", spaces) choice = input("\nDo you want to analyze another string? (yes/no): ").lower() if choice != "yes": print("Program terminated") break