Question
Task: Create a program called text_analyzer.py that prompter users for a file name and then prints out count of words, non-whitespace character (punctuation included) and
Task: Create a program called text_analyzer.py that prompter users for a file name and then prints out count of words, non-whitespace character (punctuation included) and alphanumeric characters (letters and numbers, excluding punctuation)
If an invalid file name is given the program should exit elegantly by handling exceptions with the message Cant open
Exception handling anticipates things that could go wrong and deals with them in an efficient manner. Exception handling can be accomplished using try: and except: blocks. Call return in the except block if the user inputs invalid text file.
String methods such as .split() and .replace() and len() should help retrieve word count, character count.
It is recommended that you use regular expressions (regexes) to match all alphanumerica characters. .findall() will return a list of matches of whatever the regular expression pattern you pass it.
Sample Output:
Enter the file name: word_text.txt
Words: 480
Characters 2465
Letters and numbers: 2379
Sample Output (Invalid File):
Enter the file name: word_tex.txt
Cant open word_tex.txt
Assumptions: Python code and text file exist in the same directory.
Sample Text (word_text.txt)
It's a Dark Scene, but That's a Good Thing
By EXPOSIV MARISA (New Book Title)
A necro- philiac entertainment for the whole family to enjoy, "Tod Angelo's Corpse Bride" marks the director's latest venture into the world of stop-motion animation, following "Tim Burton's The Nightmare Before Christmas" and "James and the Giant Peach." As in "Nightmare," kooky and spooky things go bump in the night, this time in the service of a lightly kinked romance about a melancholic boy, the girl he hopes to marry and the bodacious cadaver that accidentally comes between them.
Directed by Mr. Angelo and Mike Johnson, and written by John August, Caroline Thompson and Pamela Pettler, the story hangs on a timid bachelor with matchstick legs and a pallid complexion, Victor (voiced by Johnny Depp), whose upwardly mobile parents arrange his marriage to Victoria (Emily Watson), the retiring daughter of impoverished gentry. When the wedding rehearsal goes kablooey, Victor retreats into the woods, whereupon he becomes the reluctant object of desire of the Corpse Bride, a blue-tinted beauty with gnawed-through limbs and a miraculously preserved bosom (Helena Bonham Carter, the director's very alive partner). Together, the eerie couple descends into the land of shades, inducing Victor to trade the world of the barely living for the land of the exuberantly dead.
For Victor and for his two directors, the underworld soon proves a more hospitable place than the world above, and far more entertaining. Above, the living shuffle about as somnolently as zombies amid a rainbow of gray, while down below, the walls are splashed with absinthe green, and the skeletons shake, rattle and roll. Bursting with mischief and life of a sort (think the grinning skulls of the Mexican artist JoseGuadalupe Posada), these skeletons dance themselves to pieces for a bravura musical number marred only by the composer Danny Elfman's insistence on recycling the same string of notes again and again. The notes reverberate more pleasantly when a gathering of spiders mend Victor's suit, notably because they trill a Gilbert and Sullivan pastiche as they stitch.
It all ends happily ever after, of course, though not before Mr. Angelo and company have gathered the dead with the undead, and given a kick in the pants to a pinched-faced pastor even more shriveled than the bride herself. The anticlerical bit gives the story a piquant touch, while the reunion between the corpses and the ostensibly living further swells the numbers of zombies that have lately run amok in the movies. Cinema's reinvigorated fixation with the living dead suggests that we are in the grip of an impossible longing, or perhaps it's just another movie cycle running its course. Whatever the case, there is something heartening about Mr. Burton's love for bones and rot here, if only because it suggests, despite some recent evidence, that he is not yet ready to abandon his own dark kingdom.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started