class library:
def __init__(self, title, author, publication_year, price, quantity):
self.title = title
self.author = author
self.publication_year = publication_year
self.price = price
self.quantity = quantity
def display_info(self):
print(self.title, "by", self.author, "was published in", self.publication_year, ",this is the price",
self.price, "and we have this", self.quantity, "amount")
def is_old(self):
if 2025 - self.publication_year > 50:
print("the difference is:", 2025 - self.publication_year, "years")
print("old")
else:
print("the difference is:", 2025 - self.publication_year,"years")
print("not old")
def purchase(self, quantity):
if self.quantity >= quantity:
self.quantity -= quantity
return True
else:
return False
book1=Library("Before the coffee gets cold", "Toshikazu kawaguchi", 2015, 1038)
book2=Library("The Great Gatsby", "F. Scott Fitzgerald", 1925, 2739)
book1.display_info()
book2.display_info()
book1.is_old()
book2.is_old()
inventory = {}
def add_book():
title = input("Enter book title:")
author = input("Enter book author:")
publication_year = float(input("enter book publication_year:"))
price = float(input("enter book price:"))
quantity = int(input("enter book quantity:"))
book = book(title, author, publication_year, price, quantity)
inventory[name] = book
print(title,"added to inventory.")
def view_book():
if not inventory:
print("inventory is empty.")
for title, book in inventoy.items():
print("name:", book.title, "author:", book.author, "publication_year:", book.publication_year,
"price:", book.price, "quantity:", book.quantity)
def buy_book():
title = input("enter the book u wanna buy:")
if title not in inventory:
print("sorry, we dont have that book in store")
return
quantity = int(input("enter quantity to buy:"))
book = inventory[title]
if book.quantity >= quantity:
if book.purchase(quantity):
total = book.price * quantity
print("purchase succesful! total cost:", total)
else:
print("purchase failed.")
else:
print("sorry, not enough quatity available.")
def main():
while True:
print("---- vault inventory menu----")
print("1. add book")
print("2. view book")
print("3. buy book")
print("4. exit")
choice = input("choose an option: ")
if choice == "1":
add_book()
elif choice == "2":
view_book()
elif choice == "3":
buy_book()
elif choice == "4":
print("exiting... goodbye!")
break
else:
print("invalid choice. choose again.")
main()