-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.py
More file actions
70 lines (55 loc) · 1.4 KB
/
Copy pathproject.py
File metadata and controls
70 lines (55 loc) · 1.4 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
import datetime
books = []
# categories = ("Science", "Math", "History", "Story")
def add_book():
name = input("Enter book name: ")
author = input("Enter author name: ")
category = input("Enter category: ")
book = {
"name": name,
"author": author,
"category": category,
"date_added": datetime.date.today()
}
books.append(book)
print("Book added successfully")
def view_books():
if len(books) == 0:
print("No books available")
else:
print("books display",books)
def search_book():
search = input("Enter book name: ")
for b in books:
if b["name"] == search:
print("Book found:", b)
return
print("Book not found")
def delete_book():
name = input("Enter book name to delete: ")
for b in books:
if b["name"] == name:
books.remove(b)
print("Book deleted")
return
print("Book not found")
while True:
print("\nLibrary Menu")
print("1 Add Book")
print("2 View Books")
print("3 Search Book")
print("4 Delete Book")
print("5 Exit")
choice = input("Enter choice: ")
if choice == "1":
add_book()
elif choice == "2":
view_books()
elif choice == "3":
search_book()
elif choice == "4":
delete_book()
elif choice == "5":
break
else:
print("Invalid choice")