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 =[1601,1859,1922,1952,1997]
prices =[14.52,9.56,19.97,10.35,16.62]
def book_display():
print(f"{'Num':5}{'Book':40}{'Author':25}{'Year':10}{'Price':10}")
print("-"*90)
for i in range(len(books)):
print(f"{i+l:5}{books[i]:40}{authors[i]:25}{published[i]:10} ${pr
def show_purchase(book_nums):
print(f"
{'Book':40}{'Author':25}{'Year':10}{'Price':10}")
print("-"*90)
for num in book_nums:
index = num -1 # Adjust for 0-based index
print(f"{books[index]:40}{authors[index]:25}{published[index]:10} $
def totals(book_nums):
total_price == sum(prices[num -1] for num in book_nums) # Get the total pri
tax = total_price *0.05 # Calculate 5% tax
final_total = total_price + tax
return total_price, tax, final_total
def main():book_display()book_nums =[]while True:
try:
num = int(input("Enter the number of the book you want to buy: "))
if 1= num= len(books):
book_nums.append (num)
else:
print(f"Please choose a number between l and {len(books)}.")
except ValueError:
print("Invalid input. Please enter a valid number.")
another = input("Would you like to purchase another book? (y for yes): "
if another !='y':
breakshow_purchase(book_nums)total_price, tax, final_total = totals(book_nums)print(f"
Total price (before tax): ${total_price:.2f}")
print(f"Tax (5%): ${tax:.2f}")
print(f"Total (after tax): ${final_total:.2f}")if _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 2.(this happens in the main0 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.
When/if the user is done entering the numbers for the books they want to buy, the program is to call the show purchase(book_nums) function and display information of the books the user chose to purchase
Next the program is to call the totals(book_nums) function then display the resutls.
The image below provides an example of what the output should look like
How do I split this function into two and link

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!