Computer Science, asked by praveenyadav032003, 5 months ago

Write a function in Python to print those words which contains letter ‘S’ or ‘s’
anywhere in the word in text file “STORY.txt”.
If the “STORY.txt” contents are as follows:
An Old Man is happy today, he doesn’t
complain about anything, smiles, and even
his face is freshened up.
The output of the function should be:
is doesn’t smiles his is freshened

Answers

Answered by jai696
7

\large\mathsf\color{pink}{Solution\: using\: python\: 3}

def main():

words = []

with open("STORY.txt", "r") as f:

for line in f:

for word in line.split():

if "s" in word or "S" in word:

words = [*words, word]

for idx, word in enumerate(words):

if "," in word:

words[idx] = word.replace(",", "")

return " ".join(words)

print(main())

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Similar questions