Question: Create a Python program that performs detailed text analysis. Your program should be able to process a text file provided by the user through the
Create a Python program that performs detailed text analysis. Your program should be able to process a text file provided by the user through the command line. The analysis should include counting various elements of the text and displaying the results in a structured format.
Core Requirements:
Input and Output File Handling:
Open and read a file containing your lines of text
The input file name will be passed through a command line argument
Open and write to a file that will contain your analysis your results
The output file name will be passed through a command line argument
Text Analysis:
Count the number of words in the text.
Count the number of lines in the text.
Count the total number of characters including whitespace
Identify and count words that start with a capital letter.
Identify and count words that start with a lowercase letter.
Identify and count words that end with a special character period question mark, or exclamation point
Output Display:
Display the analysis results in a tabulated format on the screen.
If a category has no results, display for that category.
File Writing:
Write the analysis results to a new file as well as displaying them on the screen.
Error Handling:
Implement error handling to account for bad input such as invalid file paths or incorrect text input
Use error exceptions to manage any issues that arise during program execution.
Extra Challenge: CommandLine Arguments
Enhance your program with argparse to include commandline arguments that allow users to specify which elements of the analysis to display.
Example arguments could be:
w or words to display only the number of words.
lines to display only the number of lines.
You should create arguments for all of the options mentioned in the text analysis.
Allow your program to accept multiple files as input and perform the analysis on each file.
Tips:
Start by outlining the functions youll need to perform each task.
Test each function individually before integrating them into your main program.
Make sure to comment your code to explain your logic and choices.
This project will test your understanding of Python basics, file handling, and commandline argument parsing.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
