Commit 31b767a9 authored by Mahdi Amini's avatar Mahdi Amini

kffkfk

parent 16d7f5b2
...@@ -22,48 +22,41 @@ class Library: ...@@ -22,48 +22,41 @@ class Library:
"book": book, "book": book,
"count": count "count": count
} }
def __str__(self):
return self.title
def borrow_book(self, book):
if book.book_id in self.books and self.books[book.book_id]["count"] > 0:
self.books[book.book_id]["count"] -= 1
return True
return False
def return_book(self, book):
if book.book_id in self.books:
self.books[book.book_id]["count"] += 1
def __str__(self):
return self.title
class Student: class Student:
def __init__(self, student_id, full_name): def __init__(self, student_id, full_name):
self.student_id = student_id self.student_id = student_id
self.full_name = full_name self.full_name = full_name
self.current_book = None
self.current_library = None
def __str__(self): def borrow(self, book, library):
return self.full_name
# ...
class Borrow:
def __init__(self, student, book, library):
self.student = student
self.book = book
self.library = library
def info(self): if self.current_book:
return f"{self.student} کتاب «{self.book}» را از کتابخانه {self.library} گرفته است" self.current_library.return_book(self.current_book)
print(f"{self.full_name} کتاب قبلی را پس داد.")
book1 = Book(1, "رازآلوده", "نویسنده حسین") if library.borrow_book(book):
book2 = Book(2, "test", "author test") self.current_book = book
self.current_library = library
print(f"{self.full_name} کتاب «{book}» را گرفت.")
library1 = Library(1, "تاریخی") else:
library2 = Library(2, "ورزشی") print("کتاب موجود نیست!")
library1.add_book(book1, 3)
library2.add_book(book2, 1)
student1 = Student(1, "Ali")
borrow1 = Borrow(student1, book1, library1)
print(borrow1.info())
def __str__(self):
return self.full_name
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment