This is a simple Python script that counts the number of words in a given text file.
Prompts the user to enter a file name.
Checks if the file exists before reading.
Reads the file content and counts the total number of words.
Handles missing files gracefully without crashing.
Python 3.x
Save the script as word_counter.py.
Run the script:
python3 word_counter.py
Enter the name of the file you want to analyze (make sure it's in the same directory or provide the full path).
The script will display the number of words in the file.
Enter file name: sample.txt
Output
There are 120 words in sample.txt file.
If the file does not exist, the script will print:
Output
File doesnot exist