Write a program that will generate a personalized invitation within a text file for each guest in the guest list file using the event information found in the event details file. Put all the generated invitation files in a directory called invitations. Ensure that the name of each invitation file uniquely identifies each guest's invitation

Respuesta :

Answer:

Code:  

import os   # os module to create directory  

event_file = open("event_details.txt", "r") # Getting event file  

event_details = ""  # event details to be stored  

for row in event_file:  # traversing through the event_file  

   event_details += row    # appending event details  

os.mkdir("./invitations")   # make directory in the same parent directory  

names = open("guest_list.txt", "r") # getting names of the people  

for name in names:  # traversing through names in guest_list file

   name = name.replace('\n', '')   # removing the ending '\n' from the name  

   invitation_msg = "Hi! " + name + ", You are heartly invited in the Ceremony.\nAt " + event_details # Generating the invitation message  

   file_name = '_'.join(name.split(' '))   # Spliting name in space and joining with the '_'  

   file_path = "./invitations/" + file_name + ".txt" # Generating each file path  

   invite_file = open(file_path, "w")  # Creating the file for each name  

   invite_file.write(invitation_msg)   # Write invitation to file

Output:

Ver imagen tallinn
ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE