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
book_inventory ={
"William Shakespear": [
{"book name": "Hamlet", "year pub": 1601, "price": 14.52, "quantity": 43},
{"book name": "Macbeth", "year pub": 1606, "price": 13.45, "quantity": 50},
{"book name": "Othello", "year pub": 1604, "price": 15.30, "quantity": 37},
{"book name": "Romeo and Juliet", "year pub": 1597, "price": 12.99, "quantity": 60}
],
"Charles Dickens": [
{"book name": "A Tale of Two Cities", "year pub": 1859, "price": 9.56, "quantity": 75},
{"book name": "Great Expectations", "year pub": 1861, "price": 12.50, "quantity": 60},
{"book name": "Oliver Twist", "year pub": 1837, "price": 9.75, "quantity": 50},
{"book name": "David Copperfield", "year pub": 1850, "price": 11.25, "quantity": 48}
],
"James Joyce": [
{"book name": "Ulysses", "year pub": 1922, "price": 19.99, "quantity": 30},
{"book name": "A Portrait of the Artist as a Young Man", "year pub": 1916, "price": 13.20, "quantity": 25},
{"book name": "Dubliners", "year pub": 1914, "price": 12.00, "quantity": 35},
{"book name": "Finnegans Wake", "year pub": 1939, "price": 20.10, "quantity": 20}
],
"Ernest Hemingway": [
{"book name": "The Old Man and the Sea", "year pub": 1952, "price": 10.35, "quantity": 80},
{"book name": "A Farewell to Arms", "year pub": 1929, "price": 14.75, "quantity": 45},
{"book name": "For Whom the Bell Tolls", "year pub": 1940, "price": 13.50, "quantity": 50},
{"book name": "The Sun Also Rises", "year pub": 1926, "price": 12.99, "quantity": 55}
],
"J.K. Rowling": [
{"book name": "Harry Potter and the Philosopher's Stone", "year pub": 1997, "price": 16.62, "quantity": 100},
{"book name": "Harry Potter and the Chamber of Secrets", "year pub": 1998, "price": 22.99, "quantity": 90},
{"book name": "Harry Potter and the Prisoner of Azkaban", "year pub": 1999, "price": 23.99, "quantity": 85},
{"book name": "Harry Potter and the Goblet of Fire", "year pub": 2000, "price": 25.99, "quantity": 80}
]
}
``````
# Function to check inventory
def check_inventory():
print("Book Inventory")
print("-"*40)
for author, books in book_inventory.items():
print(f"Author: {author}")
for book in books:
print(f" Book: {book['book name']}")
print(f" Year Published: {book['year pub']}")
print(f" Price: ${book['price']:.2f}")
print(f" Quantity: {book['quantity']}')
print("-"*40)
# Function to calculate total inventory value
def calculate_total_value():
total_value =0
for books in book_inventory.values():
for book in books:
total_value += book["price"]* book["quantity"]
print(f"Total inventory value: ${total_value:.2f}")
# Main program menu
while True:
print("1. Check Inventory")
print("2. Calculate Total Value")
print("3. Exit")
choice = input("Enter your choice: ")
if choice =="1":
check_inventory()
elif choice =="2":
calculate_total_value()
elif choice =="3":
print("Exiting program.")
break
else:
print("Invalid choice. Please try again.")
if ___name__=="__main__":
main()
```
How do I link these two files together ` ` ` def

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!