#Count _the_Number_of #Words_in_a_Text_File #Python_Program #pythonlearning #pythoncode #python3 #coder #learntocode #Tutorial
Problem Description
The program takes the file name from the user and counts number of words in that file.
Problem Solution
1. Take the file name from the user.
2. Read each line from the file and split the line to form a list of words.
3. Find the length of items in the list and print it.
4. Exit.
Program Explanation
1. User must enter a file name.
2. The file is opened using the open() function in the read mode.
3. A for loop is used to read through each line in the file.
4. Each line is split into a list of words using split().
5. The number of words in each line is counted using len() and the count variable is incremented.
6. The number of words in the file is printed.