Question: Description for Python Programming Language Project 1. Your code should prompt user and ask the user to input a file name. a. Note: this file
Description for Python Programming Language Project
1. Your code should prompt user and ask the user to input a file name.
a. Note: this file name must be an existing file in the same directory on your computer when running this program, otherwise 'open' will throw an error. We haven't learned about error handling yet.
b. This file name can be any file on your computer in same directory. I used the same *.py file in my example just because i have that file, you don't have to use the same file.
2. It should read from this file name and read all the content in this file.
3. It should count the total number of lines, words, characters, and averages, and output by the format like in examples below.
a. Note we define a 'word' to be separated only by space or newline. We'll ignore all other signs like comma or period.
b. For the 2 'average' results(see example), please keep 2 decimal places as listed in the examples below.
4. All the output should go to another file, as well as printing to screen. Let's name the output file: hw5_read_and_count_output.txt. You do not need to submit this file. Only submit the python file.
Note
1. the whole point of this problem is to understand the basic skills listed in the 'objective' section. As long as you know how to use these skills, the actual count of words may differ by a little bit. In other words, you do not need to worry about the perfect count, how to handle edge cases, tricky things like that.
2. Please do not repeat yourself in the code. Google "programming DRY principle". If you already have the full file content read, you do not need to read it again and again for each count. Repeated code will get pointed deducted. Only very nice and clean code can get full points.
You may or may not follow the logic in this pseudo code (please google 'pseudo code'):
def a function():
take user input for file name
open this file and read everything in
count total char
count total words
count total lines
write the formatted result to output file
print the same lines to screen
call this function
Example output to screen:
$ python3 hw5_read_and_count.py
Enter filename: hw5_read_and_count.py
Characters: 921
Words: 88
Lines: 34
Average Characters Per Word: 10.47
Average Words Per Line: 2.59
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
