-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary_management.py
More file actions
103 lines (92 loc) · 2.86 KB
/
Copy pathlibrary_management.py
File metadata and controls
103 lines (92 loc) · 2.86 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
books = []
def login():
username = "likitha"
password = "1234"
user = input("Enter your name: ")
pwd = input("Enter password: ")
if user == username and pwd == password:
print("Login successful") # fixed spelling
return True
else:
print("Enter valid details")
return False
def add_book():
book_id = input("Enter Book id: ").strip()
author = input("Enter book Author: ").strip()
title = input("Enter book Title: ").strip()
quantity = int(input("Enter book Quantity: "))
book = {"Book ID": book_id, "Title": title, "Author": author, "Quantity": quantity}
books.append(book)
print("Book added successfully")
def search_book():
book_id = input("Enter Book ID to search").strip()
found = False
for book in books:
if book["Book ID"] == book_id:
print("\nBook Found!")
print("Book ID:", book["Book ID"])
print("Title:", book["Title"])
print("Author:", book["Author"])
print("Quantity:", book["Quantity"])
found = True
break
if not found:
print("Book not found!")
def issue_book():
book_id = input("Enter Book ID to issue").strip()
found = False
for book in books:
if book["Book ID"] == book_id:
found = True
if book["Quantity"] > 0:
book["Quantity"] -= 1
print("\nBook issued successfully!")
else:
print("\nSorry! This book is out of stock.")
break
if not found:
print("\nBook not found!")
def return_book():
book_id = input("Enter book id").strip()
found = False
for book in books:
if book["Book ID"] == book_id: # fixed typo
book["Quantity"] += 1
print("Book returned successfully")
found = True
break
if not found:
print("\nBook not found!")
def calculate_fine():
days = int(input("Enter no of days book was kept"))
allowed_days = 7
fine_per_day = 5
if days <= allowed_days:
print("No fine")
else:
fine = (days - allowed_days) * fine_per_day
print("Fine Amount =", fine)
if login():
while True:
print("\n========== LIBRARY MANAGEMENT SYSTEM ==========")
print("1. Add Book")
print("2. Search Book")
print("3. Issue Book")
print("4. Return Book")
print("5. Fine Calculation")
print("6. Exit")
choice = input("Enter Your Choice: ")
if choice == "1":
add_book()
elif choice == "2":
search_book()
elif choice == "3":
issue_book()
elif choice == "4":
return_book()
elif choice == "5":
calculate_fine()
elif choice == "6":
break
else:
print("Invalid Choice!")