PERSPECTIVE: We need practice in using files and strings and we don\'t have much
ID: 3700499 • Letter: P
Question
PERSPECTIVE: We need practice in using files and strings and we don't have much time. Thus this is a short assignment. PROBLEM BACKGROUND: Assume you're working on a contract where a company is building a mailing list (or, rather, an e-mailing list) by analyzing e-mail messages. Your task is to write a Python program that reads a file (stored in the current working directory) called mail.dat and outputs to a file called addresses.dat, one per line, every e-mail address contained inside the file. (You can see now why this assignment is titled "The Spammer's Delight Problem") For this assignment, if a whitespace delimited string of characters has an embedded commercial at sign ( inside it (that is, interior to the string), we shall consider it an e-mail address. However, any trailing commas must be trimmed from addresses. Thus the string "abc@ mtsu.edu," must appear in the output file as "abe@ mtsu.edu" with the trailing comma removed. Only commas at the end of a string are considered trailing: do not remove non-trailing commas. Do not worry about any other punctuation characters; the only editing your program must do is to remove trailing commas. IMPLEMENTATION NOTES: Use as your source file name "spammer-py". Don't forget to head your source file with the standard title line and global comments we use for all programming assignments. Be sure to have code to close0 both files that you opened. INPUTIOUTPUT: You should create your own data file(s) to initially test your program. For grading, link the file SPUB/mail.dat into your work area and use it. The command ln-s $PUB/mail.dat nail.dat will do that. (Be sure to link not copy the file into your work area.) For your output file, use the filename addresses.dat. Do not write anything to standard output (i.e., do not use any print0 function calls in your final product). The first 10 lines of your addresses.dat file should look like: mikkiflower gmail.con mikkifloweregmail.com> REQUIRED: You are to electronically submit the source program, a source program listing and run log, and the output file obtained from running your program against the sample input (see above). Once you have a working program, the following UNIX commands will do what is required: s script olall1.log s rm-f nail.dat addresses dat $ ln $PUB/mail.dat mail.dat s cat -n spanmer py $ python3 spanmer.py s cat addresses.dat exit $ handin "ola11 spammer py addresses.dat olal1l.log e sure to exit the serit ession before rying to do the handiar NOTE: You should work alone on this assignment; neither offer nor accept any additional help, except on a one-to-one basis with the instructor HINTS: Some of the string methods found in Tables 8-2 and 8-3 of the textbook will be useful in coding the solution to this problem GRADING: In addition to examining your source code and the execution results obtained byExplanation / Answer
The solution for the above question is given below with the screenshot of output.
---------------------------------------------------------------------------------------------------------------
I have kept the logic simple and output as per the question.
As i didn't have the mail.dat file i created it for testing and tested it.
If there is anything else do let me know in comments
---------------------------------------------------------------------------------------------------------------
input file : mail.dat
Compose a new email followedby@txt.net, For example,
5551234567@txt.net. Picture or video message
Compose a new email and use the recipient's
phone number, followed by video@tech.net. For example,
5551234567@tech.net
Compose a new email <followedby@txt.net>, For example,
5551234567@txt.net. Picture or video message
Compose a new email and use the recipient's
phone number, followed by <video@tech.net> For example,
5551234567@tech.net
--------------- CODE TO COPY -----------------------------------------------------------------------
spammer.py
---------------------------------------------------------------------------------------------------------------
Output :
addresses.dat
followedby@txt.net,
5551234567@txt.net.
video@tech.net.
5551234567@tech.net
<followedby@txt.net>,
5551234567@txt.net.
<video@tech.net>
5551234567@tech.net
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.