Question: Python The code I already have is pictured below as well as what I am supposed to add to it . If option 1 is

Python
The code I already have is pictured below as well as what I am supposed to add to it.
If option 1 is chosen, the program is to display the inventory in a tabular format as requested in M3Pro AND do the following:
- write the information (SAME FORMAT) to a txt report titled "enventory.txt"
- write the book information, same information displayed, into a csv file. The file is to be named "env_report.csv".
- The csv file is to have the following column names (Book Name, Author, Year Pub, Price), each piece of information is to be written under the right column.
if option 2 is chosen, do the following:
- Display the list of books (similar to how it was displayed in M3Pro)
- Ask the user to enter the book number they want to buy (exactly how it worked in M3Pro)
- Ask the user if they wish to buy another book (yes/no), again just how it worked in M3Pro.
- Once the user no longer wants to buy books (entered no), go back to main menu
if option 3 is chosen, do the following:
- Display details of books purchased, exactly how it was requested and displayed in M3Pro
- Write the purchased book details in a csv report titled "purchased.csv"
- The csv file is to have the following column names (Book Name, Author, Year Pub, Price), each piece of information is to be written under the right column.
- After writing the book information in the csv file, write the book cost, tax and total price in the csv file (Below the last populated row), see example below
if option 4 chosen, notify the user that the program will terminate and stop the program
if a value other than \(1,2,3\) or 4 is entered, display a message that notifies the user that an incorrect menu choice was entered and display the menu again.
Important points to remember...
- The program is to only terminate If the user enters 4.
- Don't forget pseudocode
- If new functions are created, don't forget to assign them docstrings ```
#function to display list of books
#lists
authors =["William Shakespeare","Charles Dickens","James Joyce","Earnest Hemingway","J.K. Rowling"]
books =["Hamlet","A Tale of Two Cities","Ulysses","The Old Man and the Sea","Harry Potter and the Philosopher's Stone"]
published =[1601,1859,1922,1952,1997]
#list of book names
#list referencing book prices
prices =[14.52,9.56,19.97,10.35,16.62]
def book_display():
'''
function displays book information. Information retrieved from 4 different lists
Returns
-------
None.
print(f'{"Num":5}{"Book":60}{"Author":30}{"Year":8}{"Price"}')
print('-'*120)
for i in range(len(authors)):
print(f'{i+l:5}{books[i]:60}{authors[i]:30}{published[i]:8}${prices[i]}')
print('-'*120)
def show_purchase(book_nums):
'''
Parameters
----------
book_nums : list, references index number for books user wants to purchase
function displays information on the books selected
Returns
-------
None.
"'
# create
print()
print(f'{"Book":60}{"Author":30}{"Year":8}{"Price"}')
print('-'*115)
for i in book_nums:
print(f'{books[i]:60}{authors[i]:30}{published[i]:8}${prices[i]}')
``````
def totals(book_nums):
'''
Parameters
----------
book_nums : list, references index number for books user wants to purchase
Returns
-------
cost : price total for books chosen
tax : 5% tax on total price
total : cost + tax
'''
pur_prices =[]
for i in book_nums:
# get prices
price = prices[i]
pur_prices.append (price)
# add cost of both books
cost = sum(pur_prices)
tax = cost *0.05
total = cost + tax
return cost, tax, total
``` File Edit Format Run Options Window Help
|import m3_functions as fn
def main():
\#display book list
fn.book_display()
book_nums =[]
run_again =' y '
While run_again =='y':
\#ask user to enter book num
book_num = int(input("
Enter number of book you want to buy: "))\# append to book_nums after subtracting 1(to get accurate index num)
\# find book info (in all lists)
book_num -=1
book_nums. append (book_num)
run_again = input("
Would you like to purchase another book? (y for yes) :")
\#pass to show_purchase function
fn.show_purchase (book_nums)
cost, tx, total \(=\mathrm{fn}^{-}\).totals (book_nums)
print("
Total price (cost of book(s)+5\% tax):")
print(f'Book(s) cost Before Tax \$\{cost:,.2f\}')
print(f'Tax \$\{tax:,.2f\}')
print(f'Total After Tax \$\{total:,.2f\}')
\# Call the main function.
if \(\underset{\operatorname{main}()}{\text { name }}==\)"__main__":
Python The code I already have is pictured below

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 Programming Questions!