The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 2 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Download a copy of the ?le fromhttp://www.pythonlearn.com/code3/romeo.txt
Write a program to open the ?le romeo.txt and read it line by line. For each line, split the line into a list of words using the split function.
For each word, check to see if the word is already in a list. If the word is not in the list, add it to the list.
When the program completes, sort and print the resulting words in alphabetical order.
HINT:
Download the text file: romeo.txt fromhttp://www.pythonlearn.com/code3/romeo.txtto your local machine. For ease, place this file in the same folder as the .py file for this assignment.
Create and initialize a list to collect unique words.
Prompt the user for the file name. Use a try-except block to exit with a user-friendly error message if there is an error opening the file name specified.
Once the file is open, use an iterative loop (e.g. “for” or “while”) to traverse each line of the file.
Use the “split” function to split the line into individual words and collect these in a list. Note – remember to check for the condition that the line may be empty, i.e. not contain any words!
Check each word against our collection of unique words. If it does not exist, add it in.
When the program has finished traversing each line in the specified file, sort the complete collection of unique words in alphabetical order by apply the “sort” function.
Remember your Python code will be graded according to our class Rubric.
Submit your Python code file. Name it “XXXX-Romeo.py” where XXXX is your name.
Write a program that categorizes each mail message by which day of the week the commit was done. To do this look for lines that start with “From”, then look for the third word and keep a running count of each of the days of the week. At the end of the program print out the contents of your dictionary (order does not matter).
The input file you will use for this is the ‘mbox.txt’ file, first introduced in Severance Section 7.3. It can be found athttp://www.pythonlearn.com/code3/mbox.txt. A shorter file for debugging can be found athttp://www.pythonlearn.com/code3/mbox-short.txt.
Remember your Python code will be graded according to our class Rubric.
Submit your Python code file. Name it “XXXX-day.py” where XXXX is your name.
Submit also a Word document showing screen shots of the various testing conditions. Good programmers test all cases, so you should make sure you show tests for erroneous inputs. Make sure you submit test results from the full mbox.txt file (and not from the mbox-short.txt file.)
Be sure to comment your program adequately!
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll