Computer Science, asked by praveenyadav032003, 4 months ago

Write a function WordCount() in Python to read a text file “Mydiary.txt” and
display no of words present in each line.
Example:
If the file content is as follows:
Updated information
As simplified by official websites.
The function should display the output as:
Line No 1 : Words=2
Line No 2 : Words=5

Answers

Answered by jai696
4

\huge\red{\mid{\fbox{\tt{Using\: Python\: 3}}\mid}}

def WordCount(file):

with open(file) as f:

for idx, line in enumerate(f):

print(f"Line No {idx + 1}: Words = {len(line.split())}")

WordCount("Mydiary.txt")

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

Similar questions