-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15.py
More file actions
44 lines (42 loc) · 1.1 KB
/
15.py
File metadata and controls
44 lines (42 loc) · 1.1 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class Book:
def __init__(self,title,author,borrowed=False):
self.title=title
self.author=author
self.borrowed=borrowed
def info(self):
if self.borrowed:
print(f'Book: {self.title} by {self.author} | Borrowed')
else:
print(f'Book: {self.title} by {self.author} | Available')
class Library:
def __init__(self):
self.books=[]
def add_book(self,book):
self.books.append(book)
print(f'Book added: {book.title}')
def show_books(self):
for book in self.books:
book.info()
def borrow_book(self,title):
for book in self.books:
if book.title==title:
if book.borrowed:
print(f'You borrowed {self.title}')
else:
book.borrowed==True
print(f'Book already borrowed')
def return_book(self,title):
for book in self.books:
if book.title==title:
book.borrowed=False
print(f'Book returned: {book.title}')
b1=Book("Python Basics","John")
b2=Book("AI Guide","Andrew")
lib=Library()
lib.add_book(b1)
lib.add_book(b2)
lib.show_books()
lib.borrow_book("Python Basics")
lib.show_books()
lib.return_book("Python Basics")
lib.show_books()