Tutorials  Articles  Notifications  Login  Signup


VK

Vikash Kale

Programmer and Software Engineer at Tata Consultancy Services Updated Jan. 1, 2021, 6:24 p.m. ⋅ 1873 views

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



HackerFriend Logo

Join the community of 1 Lakh+ Developers

Create a free account and get access to tutorials, jobs, hackathons, developer events and neatly written articles.


Create a free account