|
| 1 | +''' |
| 2 | +Author: Aditya Mangal |
| 3 | +Date: 16 september,2020 |
| 4 | +Purpose: python mini project |
| 5 | +
|
| 6 | +''' |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +from win32com.client import Dispatch |
| 11 | + |
| 12 | +class library: |
| 13 | + |
| 14 | + def __init__(self, list, name): |
| 15 | + |
| 16 | + self.book_list = list |
| 17 | + self.name = name |
| 18 | + self.lend_dict = {} |
| 19 | + |
| 20 | + def display_books(self): |
| 21 | + print(f"{self.name} library has: ") |
| 22 | + for books in self.book_list: |
| 23 | + print(books) |
| 24 | + |
| 25 | + def lend_book(self, user, book): |
| 26 | + |
| 27 | + if book not in self.lend_dict.keys(): |
| 28 | + self.lend_dict.update({book: user}) |
| 29 | + print('Database updated . you can now lend the book.') |
| 30 | + |
| 31 | + else: |
| 32 | + print(f"the book is already lend by {self.lend_dict[book]}.") |
| 33 | + |
| 34 | + def return_book(self, book): |
| 35 | + if book not in self.lend_dict.keys(): |
| 36 | + print('Not Returnable. Check twice') |
| 37 | + else: |
| 38 | + self.lend_dict.pop(book) |
| 39 | + print('Book returned successfuly.\n') |
| 40 | + |
| 41 | + def add_book(self, book): |
| 42 | + self.book_list.append(book) |
| 43 | + print('Book added successfully.') |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == '__main__': |
| 47 | + speak = Dispatch("SAPI.spvoice") |
| 48 | + speak.speak("Welcome to the Library") |
| 49 | + print('\t\t **Welcome to Library** \t\t\n') |
| 50 | + |
| 51 | + obj = library([ |
| 52 | + 'python', 'Let us C', 'C++', 'compiler design', 'java', 'web designing'], 'Aditya Mangal') |
| 53 | + |
| 54 | + while True: |
| 55 | + |
| 56 | + user = int(input( |
| 57 | + "what you want you do?\nPress 1 to display the books in the library.\nPress 2 to lend a book from library.\nPress 3 to return a book.(Return the book in given time to ignore late fine)\nPress 4 to add a book.\n")) |
| 58 | + |
| 59 | + if user is 1: |
| 60 | + |
| 61 | + obj.display_books() |
| 62 | + |
| 63 | + elif user is 2: |
| 64 | + user_name = input('Enter your name.\n') |
| 65 | + user_book = input('Enter the book name u want to lend.\n') |
| 66 | + obj.lend_book(user_name, user_book) |
| 67 | + |
| 68 | + elif user is 3: |
| 69 | + returning_book = input('Enter the book you want to return.\n') |
| 70 | + obj.return_book(returning_book) |
| 71 | + |
| 72 | + elif user is 4: |
| 73 | + adding_book = input('Enter the book you want to add.\n') |
| 74 | + obj.add_book(adding_book) |
| 75 | + |
| 76 | + else: |
| 77 | + print('Something gone wrong! Please check again.') |
| 78 | + |
| 79 | + user_input = int( |
| 80 | + input('Want something more?\nPress 1 to continue.\nPress 2 to exit.\n')) |
| 81 | + |
| 82 | + if user_input is 1: |
| 83 | + |
| 84 | + continue |
| 85 | + |
| 86 | + else: |
| 87 | + |
| 88 | + exit() |
0 commit comments