TCS NQT/Digital coding program 2 - Write an program to count no of words, spaces, vowel and character.
Solution Code: -
sentence = input("Enter a sentence with few strings: ")
len_of_sentence = len(sentence)
vowel_list = ['a','e','i','o','u']
space_count = sentence.count(' ')
char_count = len_of_sentence - space_count
word_count = len(sentence.split())
vowel_count = len([char_i for char_i in sentence if char_i.lower() in vowel_list])
print("words",word_count)
print("spaces",space_count)
print("characters",char_count)
print("vowels",vowel_count)
For Reference Click on - Program_Code_video