1+ from typing import SupportsIndex
2+ import termcolor
3+ class Library :
4+ def __init__ (self ,book_category ):
5+ self .books = book_category
6+
7+ def intro (self ):
8+ message = """\n \t ****** Welcome To Anime Vyuh Library ******\n 1. List Of Books\n 2. Request A Book\n 3. Return A Book\n 4. Exit"""
9+ print (f"\t { message } " )
10+
11+ def listofbooks (self ):
12+ print ("\t *** Here Are The List Of Book *** " )
13+ for index ,book in enumerate (self .books ,start = 1 ):
14+ print (f"{ index } :{ book } " )
15+
16+ def returnbook (self ,bookname ):
17+ if bookname not in self .books :
18+ self .books .append (bookname )
19+ termcolor .cprint ("\n Thank You For Returning Book Back" ,color = "green" )
20+ termcolor .cprint (f"{ bookname } book is added" ,color = "blue" )
21+ else :
22+ termcolor .cprint ("\n Book Exists" ,color = "yellow" )
23+
24+ def requestbook (self ,bookname ):
25+ if bookname in self .books :
26+ self .books .remove (bookname )
27+ termcolor .cprint (f"\n { bookname } book is borrowed" ,color = "blue" )
28+ termcolor .cprint ("Enjoy Your Read" ,color = "green" )
29+ else :
30+ termcolor .cprint ("\n Sorry We Don't Have Such Book" ,color = "yellow" )
31+
32+ class Student :
33+ def __init__ (self ,id ):
34+ self .usn = id
35+
36+ def askuser (self ):
37+ ask = int (input ("\n Enter Your Choice:" ))
38+ return ask
39+
40+ def return_book (self ):
41+ request_b = input ("\n Which book could you like to return?" )
42+ return request_b
43+
44+ def request_book (self ):
45+ borrow = input ("\n Which book could you like to borrow?" )
46+ return borrow
47+
48+ if __name__ == '__main__' :
49+ scan_id = input ("Enter your id:" )
50+ student = Student (scan_id )
51+ books = ['Automate Stuff With Python' ,'EcmaJavascript' ,'ProGit' ,'Java Fundamentals' ,'Arduino With C' ]
52+ library_books = Library (books )
53+ while True :
54+ try :
55+ library_books .intro ()
56+ choice = student .askuser ()
57+ if choice in range (1 ,5 ):
58+ if choice == 1 :
59+ library_books .listofbooks ()
60+ elif choice == 2 :
61+ library_books .requestbook (student .request_book ())
62+ elif choice == 3 :
63+ library_books .returnbook (student .return_book ())
64+ elif choice == 4 :
65+ print ("\n Thank you for visting! \n Happy Reading" )
66+ exit ()
67+ else :
68+ termcolor .cprint ("Enter A Valid Choice between (1-4)" ,color = "red" )
69+ except ValueError :
70+ termcolor .cprint ("Invalid Choice" ,color = "red" )
0 commit comments