Question: How do I link these two files together ` ` ` def main ( ) : # Creating the inventory dictionary book _ inventory =
How do I link these two files together
def main:
# Creating the inventory dictionary
bookinventory
"William Shakespear":
book name": "Hamlet", "year pub": "price": "quantity":
book name": "Macbeth", "year pub": "price": "quantity":
book name": "Othello", "year pub": "price": "quantity":
book name": "Romeo and Juliet", "year pub": "price": "quantity":
"Charles Dickens":
book name": "A Tale of Two Cities", "year pub": "price": "quantity":
book name": "Great Expectations", "year pub": "price": "quantity":
book name": "Oliver Twist", "year pub": "price": "quantity":
book name": "David Copperfield", "year pub": "price": "quantity":
"James Joyce":
book name": "Ulysses", "year pub": "price": "quantity":
book name": "A Portrait of the Artist as a Young Man", "year pub": "price": "quantity":
book name": "Dubliners", "year pub": "price": "quantity":
book name": "Finnegans Wake", "year pub": "price": "quantity":
"Ernest Hemingway":
book name": "The Old Man and the Sea", "year pub": "price": "quantity":
book name": "A Farewell to Arms", "year pub": "price": "quantity":
book name": "For Whom the Bell Tolls", "year pub": "price": "quantity":
book name": "The Sun Also Rises", "year pub": "price": "quantity":
JK Rowling":
book name": "Harry Potter and the Philosopher's Stone", "year pub": "price": "quantity":
book name": "Harry Potter and the Chamber of Secrets", "year pub": "price": "quantity":
book name": "Harry Potter and the Prisoner of Azkaban", "year pub": "price": "quantity":
book name": "Harry Potter and the Goblet of Fire", "year pub": "price": "quantity":
# Function to check inventory
def checkinventory:
printBook Inventory"
print
for author, books in bookinventory.items:
printfAuthor: author
for book in books:
printf Book: bookbook name'
printf Year Published: bookyear pub'
printf Price: $bookprice:f
printf Quantity: bookquantity
print
# Function to calculate total inventory value
def calculatetotalvalue:
totalvalue
for books in bookinventory.values:
for book in books:
totalvalue bookprice bookquantity
printfTotal inventory value: $totalvalue:f
# Main program menu
while True:
print Check Inventory"
print Calculate Total Value"
print Exit"
choice inputEnter your choice:
if choice :
checkinventory
elif choice :
calculatetotalvalue
elif choice :
printExiting program."
break
else:
printInvalid choice. Please try again."
if namemain:
main
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
