5:28 K Back Hwrk06,pdf Q If we look closely at Program 6-15, we will notice that there are only two things that we must change if we wish to make it into a Module containing a function that we will use in the driver program. First we must change the name of the main function to another name. We will use the name: add_coffee() as the name of what was called main)- * The second thing we must do is to delete the very last line of this program ine 32, main()), as this module will not call this function, rather it will be the driver program which calls this function Once we have made these two changes, then the program which was labelled Program6-15, we will call module: Lastnomefirstinitial coffiee records.py, and it will contain a function, add coffee), that we will be using in the Driver program Program 6-15 (add coffee_record py) 1 This program adds coffee inventory records to 2 # th@ coffee. txt file 4 det nain) Create a variable to control the loop. another ' Opene coffee coffee tile open( coffee.txt. #Add records to the file 12 13 14 15 16 17 18 19 20 21 Get the coffee record data. print( Enter the folloving coffee datas"1 descr input ( Descriptions t Append the data to the file coffee file.write(descr' coffee file.writelatriqty) Appen Determine whether the user vants to add i another record to the file print Do you vant to add another reoord?") anotherInput( 'Y -yes, anything else 27 28 i Close the file. coffee_file.cloael) print( Data appended to coffee.txt 30 31 Call the main function Program 6-15 Results Dashboard Calendar To Do Notifications Inbox 5:28 Back Hwrk06.pdfa Program Output (with input shown in bold) Enter the folloving coffee data Description: Brazilian Dark Roast Quantity (in pounds) : 18r Do you want to enter another record2 xyes, anything else -nosy t Description: Sumatra Medium Roast Quantity (in pounds): 25 Do you want to enter another record? Y yes, anything else nos n Data appended to coftee.txt Homework 06 Cont. Now that we have one module, we are going to write the driver for this module: YourName-Hwrk06.py Initially, this driver will just run this first module. However, after you've got the first module working, you will be expanding this driver to include 4 additional modules. Below is the essence of the driving program which will run this File Management System to test and run the module LastnameFirstinitial coffee_records.py YourName-Lab06. nagement Program Calendar To Do Inbox 5:29 Back Hwrk06.pdf Q # Your Name # A Coffee File Management Program import Valdez)-coffee-records # Here's where we import th ADD COFFEE CHOICE 1 # Define Global constants fo # Which includes the choice QUIT_CHOICE 6 def main(): choice0 while choice!-QUIT_CHOICE: display menu() choice = int(input('Enter your choice:1) if choiceADD_COFFEE_CHOICE: Valdezl coffee recordsadd-coffee() print(Exiting the progra...) print('Error: invalid selection.') # We call the fun elif choice QUIT-CHOICE else: def display_menu0 print(JUAN VALDEZ COFFEE MANAGEMENT MENU) print'1) Add more Coffee Choices to List'T print(6) Quit') main() Home Once you have the first will repeat what you did Program 6-16, which co Then you will expand th this additional module Calendar To Do Inbox 5:29 Back Hwrk06.pdfa QUIT CHOICE linputfEnber your choice ADD COFFEE CHOE QUIT CHOICE ror: invalid selection VALDEZ COFFEE MANAGEMENT MENU more Coffee Choices to List Homework 06 Cont. Once you have the first module up and running, now you will repeat what you did and add to the module, the second Program 6-16, which contains the function show_coffee(). Then you will expand the driver program menu to include this additional module You will also import this module You will change the menu to indlude this module Once the second function is working, repeat the preceding 3 more times to include: Program 6-17, Program 6-18 and Program 6-19 From these three programs you will be adding the following functions to your module: LastnameFirstinitial coffee records search_coffee) modify_coffee) Modify your driver program to accommodate these additions progran dispiaye the oetfee.sxt ie Program 6-16 oed the EL Pcoreaerieion tinia. Displaying all the records i he tile quaity field. Calendar To Do Inbox 5:291 Back Hwrk06.pdfa Program 6-16 (show coffee, 1 This progran displays the records in the 2 coffee.txt file. 4 def sain): t Open the coffee.txt file. coffee file open( eoffee.tzt Read the fir t record's description field. descr coffee file.readline) 10 #Read the rest of the file hile deser 12 13 14 15 16 17 18 19 20 21 Read the quantsty seld. gty float(coffee file. readline)) # Strip the Vn from the description. descr descr.rstrip( La Display the record. print('Description:, descr) print 'Quantitysqty 23 24 25 26 27 28 29 Read the next description. descr coffee file.readline) l Close the file coffee tile.close Call the main function Program 6-1 This program allows the user to m Program 6-17 (search coffee_records.py) # This program allows the user to 2 coffee.txt file for records matc # description To Do Inbox 5:29 Back Hwrk06.pdfa This program allows the user to search the 2 coffee.txt file for records matching a 3 description. 5 def main) create a bool variable to use as a flag found -Palse t Get the search value 10 Bearchinput( 'Enter a description to search for: 12 13 14 15 16 17 18 # Open th@ coffee.txt file. coffee file open(coffee.txt Read the first record's deseription field. descr coffee file.readline) i Read the rest of the file Read the qoantity Eield. gey-float(eoftee file readlineD Strip the in fron the dencription. deser deser.rstript in Progra Determine vbether this record natches f the beareh value. Searc Dieplay the record. printl'Deseriptiom*deser) print('ouancitysqty) print) Set the found flag to Trve found Progran Output (wh input th descr- cotfee tile.readline) Close the fse. ga Output (with input eoftee file.elosetD * If the 0arets value was not found in th fil.e display Mssage print('7hst item was not found in thfile To Do Inbox 5:30 Back Hwrk06.pdfa Program 618 (modify c This progran allows the eser to modify the quantity 2in a record in the eoffee.txt file. 4 import os # Needed for the remove and renane functions 6 def main #create a bool variable to use as a flag found-Palse 10 Get the seareh value and the ev quantity search- input( 'Eater a desexiption to search for: nev qty float (input("Enter the neu quantity: 13 # open the original coffee.txt file. coffee tileopeal'coffee.txt" 16 17 Open the temporary file temp file open( temp.txt.) 19 Read the first record's deseription field. deser coffee file.readlinet) 21 t Read the rest of the file 24 25 26 27 28 t Read the quantity field. gty float(coffee file.readline0) # Strip the la fron the descriptio. deser deser.rstrip( Ln' 30 31 4 write either this record to the temporary fil i or the nev record if this is the one that is t to be nodified. if deserseazch: 35 36 write the modified record to the top fil temp-file-write(descr + *.) temp file.write(str(nev-gty) 38 set the found fla to true. found True To Do Inbox 5:30 Back Hwrk06.pdfa t to be nodified if descrsearch: 35 36 37 38 Write the modified record to the temp file tempt ile-write(descr + *ln') temp file.vrite(str(ev tya Set the found flag to True. found -True 41 # write the original record to the temp file temp file.vrite(descrn temp file.vrite(str(gty)+n 43 45 Read the next description. descr coffee file. readlileo ary ti 50 coffoe file.close) temp file.close( @ Delete the original coffee.txt tile. os. remove( coffee.txt Renane the temporary file. oa.rename( temp.txt. coffee.txt 57 If the earch value wan t found n the file 59 60 61 display a message if found: print( The file has been epdated. 63 else: print(That item vas not found in the file 65 66 Call the main function. 67 maia) Program Output (with input shown in bold Enter a deacription to aearch for: Brazillan Dark Roast Ene Enter the new quantity: 10 Tm The file has been updated Program 6-19: Deleting a Record from a File This progran allows the user to delete To Do Inbox 5:31 Back Hwrk06.pdf Q r a description to search fors Brazilian Dark Roast Entr r the new quantity: 10 Ee file has been updated Program 6-19: Deleting a Record from a File 1This progran allows the user to delete 2 t a record in the coffee.txt file. nport O@ Needed for the renovo and renan0 funetion8 Create a bool variable to use as &flag found-False # Get the coffee to delete. search-input("Which coffee do you vant to delete? 10 12 # open the original eottee.t ! ile. 14 coffee ile open('coffee.txt. 16 lOpen the tenporary file. tesp-file-open(.tesp.txt . , .v. 18 19 20 Read the firt record' description field. descr coffee file.readlinet) Program 6-19: Deleting a Record from a File Cont. #Road the rest of the file. while descr 23 24 25 26 27 28 29 30 31 32 Read the quantity field qty - float (coffee file.readline)) Strip the In from the description descrdescr.zstript La If this is not the record to delete, # write it to the terporary file if descr - search: #write the record to the temp file temp file.vrite(descra 34 Calendar To Do Inbox 5:31 Back Hwrk06.pdfa gram 6-19: Deleting a Record from a File Cont. # Read the rest of the file while deser : Read the quantity field. ty float(coffee file.readline()) Strip the n from the deseription descrdescr.stript'La If this is not the record to delete, then write it to the temporary file. if descr search write the record to the temp file teap file.write(descra) temp file.write(str(gty)) else: # set the found flag to True found-True Read the next description descr coffee file.readline) ram 6-19: Deleting a record from a file concluded 43 # Clos@ the coffee file and tb@ te porary fil@. coffee file.elose temp file close 45 46 47 48 49 50 51 52 53 54 Delete the oziginal coffee.txt file os.removel coffee.txt # Rename the temporary file. os.renane temp.txt.coffee.txt i If tbe search value was not found in the file di play a message if found 56 57 58 59 60 # Call the nain function. print( The file has been updated. else: print('That iton was not tound che file.") Calendar To Do Inbox 5:31 K Back Hwrko6.pd d 45 46 47 48 49 s0 51 52 53 54 temp file.close Delete the original coffee.txt file. os.removel coffee.txt') l Renane the tenporary file. os. renanel temp.txt'. coffee.tat) I If the search value was not found ia the file diaplay a message. if foundi 56 57 58 59 60 t Call the main function. 61 nain() print( The file has been updated. ) else: print( That item was not found in the tile Program Output (with input shown in bold) Which coffee do you want to delete? Brazilian Dark Roast E The file has been updated Homework 06 Concluded ere is what the Homework6 menu should look like However, substitute your name for that of Juan Valdez. UAN VALDEZ COFFEE MANAGEMENT MENU 1) Add more Coffee Choices to List 2) Display all the Coffee Choices 3) Search Coffee Choices 4) Modify Coffee Choices 5) Delete a Coffee Choice 6) Quit Enter your choice: Dashboard Calendar To Do Notifications Inbox