CBSE BOARD XII, asked by eshitabarhate12345, 2 days ago

Write a Python program that reads a line, then counts words and displays the total number of words in the given line.

Answers

Answered by ahanazx11
0

Explanation:

Use str. split() to count the lines, word, and characters within a text file

file = open("sample.txt", "r")number_of_lines = 0.number_of_words = 0.number_of_characters = 0.for line in file:line = line. strip("\n") won't count \n as character.words = line. split()number_of_lines += 1.

Similar questions