-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook.py
More file actions
32 lines (24 loc) · 966 Bytes
/
Copy pathbook.py
File metadata and controls
32 lines (24 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Book:
def __init__(self,title,author,isbn,quantity):
self.title = title
self.author = author
self.isbn = isbn
self.quantity = quantity
self.active = True
def show_info(self):
return f"Title: {self.title}, Author: {self.author}, ISBN: {self.isbn}, Quantity: {self.quantity}"
def update_quantity(self,quantity):
self.quantity += quantity
print(f"Quantity of {self.title} changed to {self.quantity}")
def borrow(self,quantity):
if self.quantity >= quantity:
self.quantity -= quantity
print(f"Quantity of {self.title} changed to {self.quantity}")
else:
raise ValueError(f"amount of {self.title} is less than your request")
def is_active(self):
if self.quantity != 0:
self.active = True
print(f"{self.title} is activated.")
else:
print(f"{self.title} is deactivated.")