-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.py
65 lines (52 loc) · 1.97 KB
/
library.py
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
class Library():
def __init__(self, booklist):
self.book = booklist
def allBooks(self):
print("The books present in the Library are as follows: \n")
for book in self.book:
print("\t*" + book)
def borrow(self,bookname):
if bookname in self.book:
print(f"Thanks for visiting our library. Please take care of the book you borrowed - '{bookname}'. Please return it within 30 days.\n")
self.book.remove(bookname)
return True
else:
print("The book you are trying to borrow is not available \n")
return False
def returnBk(self,bookname):
if bookname != self.book:
self.book.append(bookname)
print("Thanks for visiting our Library. Visit again!")
else:
print("This book is not beign issued. Thanks for visiting Worlds Library")
class Student:
def requestedbooks(self):
reqbook = input("Enter the name of the book you want to borrow : ")
return reqbook
def returnedbooks(self):
retnbook = input("Enter the name of the book you want to return : ")
return retnbook
if __name__ == '__main__':
myLib = Library(["python", "java", "flutter", "C",
"javascript", "c++", "react", "django"])
student = Student()
while(True):
welcomeMsg = ''' \n * * * * * WORLD LIBRARY * * * * * \n
Please choose an option:
1. List all available books
2. Request books
3. Return books
4. Exit the Library \n
'''
print(welcomeMsg)
opt = int(input("Please enter the option number : "))
if opt == 1:
myLib.allBooks()
elif opt == 2:
myLib.borrow(student.requestedbooks())
elif opt == 3:
myLib.returnBk(student.returnedbooks())
elif opt == 4:
exit()
else:
print("Not a valid option. Please choose from 1-4. ")