Skip to content

Instantly share code, notes, and snippets.

@TanjimReza
Created May 2, 2023 17:26
Show Gist options
  • Save TanjimReza/edd7f1fc55fca1a4b5041d0a22d8bcda to your computer and use it in GitHub Desktop.
Save TanjimReza/edd7f1fc55fca1a4b5041d0a22d8bcda to your computer and use it in GitHub Desktop.
#!!! INCOMPLETE
class Library:
Total_book = 1000
borrow_data = {}
def __init__(self,n,id):
self.student_name = n
self.student_id = id
def borrowbook(self):
print("A book is borrowed!")
def __str__(self):
return "Library: XYZ"
class Student(Library):
def __init__(self, name, id):
self.name = name
self.id = id
self.borrowed_books = []
def borrowbook(self, book_name, book_id = None):
super().borrowbook()
print(f"{book_name} with unique id {book_id} is borrowed by {self.name}({self.id})")
Library.Total_book -= 1
self.borrowed_books.append(book_name)
print(f"Number of books available for borrowing: {Library.Total_book}")
Library.borrow_data[book_name] = self.name
def __str__(self):
s = super().__str__()
s += f"\nStudent Name: {self.name} ID: {self.id}"
s += f"\nBooks borrowed: {', '.join(self.borrowed_books)} "
return s
# return super().borrowbook()
def returnAllBooks(self):
print("All books are returned!")
#Write your code here
s1 = Student("Alice",18101259)
s1.borrowbook("The Alchemist", "Hdw652")
print("===============")
print(s1)
print("===============")
print(Library.borrow_data)
print("===============")
s1.borrowbook("Wuthering Heights")
print("===============")
print(s1)
print("===============")
s2= Student("David",18141777)
s2.borrowbook("The Alchemist", "Hdw652")
print("===============")
s2.borrowbook("The Vampyre")
print("===============")
print(Library.borrow_data)
print("===============")
s1.returnAllBooks()
print("===============")
print(Library.borrow_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment