Question: *PYTHON* Write a program that reads in two files: a template and a database and writes junk mails (save your outputs as the .txt format)

*PYTHON*

Write a program that reads in two files: a template and a database and writes junk mails (save your outputs as the .txt format) using the template email format.

The template file contains text and tags. The tags have the form |1| |2| |3| and need to be replaced with the first, second, third, field in the current database record. A typical database looks like this:

Mr.|Harry|Morgan|1105 Torre Ave.|Cupertino|CA|95014

Dr.|John|Lee|702 Ninth Street Apt. 4|San Jose|CA|95109

Miss|Evelyn|Garcia|1101 S. University Place|Ann Arbor|MI|48105

And here is a typical form letter:

To:

|1| |2| |3|

|4|

|5|, |6| |7|

Dear |1| |3|:

You and the |3| family may be the lucky winners of $10,00,000 in the Python

clearinghouse sweepstakes. Please visit our offices in |5|, |6| to

confirm your winning status.

Sincerely,

Scammers

Given that there are three people in the database file, your program should be able to generate three junk mails automatically. For your output files (i.e., three junk mails), ensure to save the name as first name + last name.txt. In other words, once I execute your codes, there will be three files generated automatically with the file names of HarryMorgan.txt, HarryMorgan.txt, and JohnLee.txt in my side.

(Tips: use .replace() to replace the value and use .write() to write into the junk mail template; use .read() to extract a string that contains characters in the file).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!