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

kffkfk

parent 16d7f5b2
......@@ -6,13 +6,13 @@ class Book:
def __str__(self):
return f"{self.title} - {self.author}"
class Library:
def __init__(self, library_id, title):
self.library_id = library_id
self.title = title
self.books = {}
self.books = {}
def add_book(self, book, count):
if book.book_id in self.books:
......@@ -22,48 +22,41 @@ class Library:
"book": book,
"count": count
}
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:
def __init__(self, student_id, full_name):
self.student_id = student_id
self.full_name = full_name
self.current_book = None
self.current_library = None
def __str__(self):
return self.full_name
# ...
class Borrow:
def __init__(self, student, book, library):
self.student = student
self.book = book
self.library = library
def info(self):
return f"{self.student} کتاب «{self.book}» را از کتابخانه {self.library} گرفته است"
def borrow(self, book, library):
if self.current_book:
self.current_library.return_book(self.current_book)
print(f"{self.full_name} کتاب قبلی را پس داد.")
book1 = Book(1, "رازآلوده", "نویسنده حسین")
book2 = Book(2, "test", "author test")
library1 = Library(1, "تاریخی")
library2 = Library(2, "ورزشی")
library1.add_book(book1, 3)
library2.add_book(book2, 1)
student1 = Student(1, "Ali")
borrow1 = Borrow(student1, book1, library1)
print(borrow1.info())
if library.borrow_book(book):
self.current_book = book
self.current_library = library
print(f"{self.full_name} کتاب «{book}» را گرفت.")
else:
print("کتاب موجود نیست!")
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