Computer Science, asked by ashwinibnithiyananda, 8 months ago

Write a program to enter a sentence in uppercase then print all the words along with number of vowels in it. Also print the words which start and ends with same alphabet

Answers

Answered by ghulamsarvar
0

Answer:

You didnt mentioned programming language, so i will be using Python for the problem statement.

Explanation:

import re;

inputString = 'THIS IS A DEMO STRING, REALLY EWE?';

formattedString =  re.sub('[^A-Z]+', ' ', inputString);     #to remove any sp char

wordList = formattedString.split();

print("RAW STRING       : " + inputString)

print("FORMATTED STRING : " + formattedString)

print("SPITTED STRING   : " + str(wordList))

vowels = 'AEIOU';

firstLastSmae = [];

for word in wordList:

   print(word +" Contains : "+ str(len([each for each in word if each in vowels])) + " vowels" );

   if(word[0] == word[-1]):

       firstLastSmae.append(word);

print("WORDS WITH SAME START AND END CHARACTES : " +str(firstLastSmae));

Output :

RAW STRING       : THIS IS A DEMO STRING, REALLY EWE?                                                                            

FORMATTED STRING : THIS IS A DEMO STRING REALLY EWE                                                                              

SPITTED STRING   : ['THIS', 'IS', 'A', 'DEMO', 'STRING', 'REALLY', 'EWE']                                                        

THIS Contains : 1 vowels                                                                                                        

IS Contains : 1 vowels                                                                                                          

A Contains : 1 vowels                                                                                                            

DEMO Contains : 2 vowels                                                                                                        

STRING Contains : 1 vowels                                                                                                      

REALLY Contains : 2 vowels                                                                                                      

EWE Contains : 2 vowels                                                                                                          

WORDS WITH SAME START AND END CHARACTES : ['A', 'EWE']

Similar questions