-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrarymanagementsystem.py
More file actions
79 lines (66 loc) · 2.32 KB
/
librarymanagementsystem.py
File metadata and controls
79 lines (66 loc) · 2.32 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import sys
# ===== OOP: Inheritance və Polymorphism üçün əsas sinif =====
class User:
def action(self):
print("User is doing something...")
class Student(User): # Inheritance: Student <- User
def action(self):
print("Student is requesting a book.")
def requestBook(self):
print("Enter the name of the book you would like to check out:")
self.book = input()
return self.book
def returnBook(self):
print("Enter the name of the book you want to return:")
self.book = input()
return self.book
class Admin(User): # Inheritance: Admin <- User
def action(self):
print("Admin is adding books or managing inventory.")
# ===== Library sinifi: Encapsulation + Class/Object prinsipini daşıyır =====
class Library:
def __init__(self, listofbooks):
self.availablebooks = listofbooks # Encapsulation
def displayAvailablebooks(self):
print("\nThe books we have in our library are:")
for book in self.availablebooks:
print(book)
def lendBook(self, requestedBook):
if requestedBook in self.availablebooks:
print("You have now borrowed the book.")
self.availablebooks.remove(requestedBook)
else:
print("Sorry, it is not available in the library.")
def addBook(self, returnedBook):
self.availablebooks.append(returnedBook)
print("Thanks for returning the book.")
# ===== Main Proqram =====
def main():
library = Library(["The Last Battle", "The Screwtape Letters", "The Great Divorce"])
user = Student() # Polymorphism: istəsək Admin də edə bilərik
done = False
while not done:
print("""
======== LIBRARY MENU ========
1. Display all available books
2. Request a book
3. Return a book
4. Exit
""")
try:
choice = int(input("Enter a choice: "))
except ValueError:
print("Please enter a number!")
continue
if choice == 1:
library.displayAvailablebooks()
elif choice == 2:
library.lendBook(user.requestBook())
elif choice == 3:
library.addBook(user.returnBook())
# Polymorphism burada işləyir
elif choice == 4:
sys.exit()
else:
print("Invalid choice. Try again.")
main()