Question: How do I split this function into two and link them to show like this authors = [ William Shakespeare, Charles Dickens, James Joyce,
How do I split this function into two and link them to show like this
authors William Shakespeare", "Charles Dickens", "James Joyce", "Earnest Hem
books Hamlet "A Tale of Two Cities", "Ulysses", "The Old Man and the Sea",
published
prices
def bookdisplay:
printfNum:Book:Author:Year:Price:
print
for i in rangelenbooks:
printfil:booksi:authorsi:publishedi: $pr
def showpurchasebooknums:
printf
Book:Author:Year:Price:
print
for num in booknums:
index num # Adjust for based index
printfbooksindex:authorsindex:publishedindex: $
def totalsbooknums:
totalprice sumpricesnum for num in booknums # Get the total pri
tax totalprice # Calculate tax
finaltotal totalprice tax
return totalprice, tax, finaltotal
def main:bookdisplaybooknums while True:
try:
num intinputEnter the number of the book you want to buy:
if num lenbooks:
booknums.append num
else:
printfPlease choose a number between l and lenbooks
except ValueError:
printInvalid input. Please enter a valid number."
another inputWould you like to purchase another book? y for yes:
if another y:
breakshowpurchasebooknumstotalprice, tax, finaltotal totalsbooknumsprintf
Total price before tax: $totalprice:f
printfTax : $tax:f
printfTotal after tax: $finaltotal:fif mame "main": After displaying the list of books, the program is to ask the user to enter the number for the book they want to purchase. For instance if they want "A Tale of Two Cities" the user is to enter this happens in the main function
Next, the program is to ask the user if they wish to purchase another book. If they do the program is to ask the user to enter the number for the next book they want to purchase.
Whenif the user is done entering the numbers for the books they want to buy, the program is to call the show purchasebooknums function and display information of the books the user chose to purchase
Next the program is to call the totalsbooknums function then display the resutls.
The image below provides an example of what the output should look like
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
