File tree Expand file tree Collapse file tree 1 file changed +74
-0
lines changed
Expand file tree Collapse file tree 1 file changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+
2+
3+ books = []
4+
5+ def add_book():
6+ book_id = input("Enter Book ID: ")
7+ title = input("Enter Book Title: ")
8+ author = input("Enter Author Name: ")
9+ price = input("Enter Book Price: ")
10+
11+ books.append({
12+ "id": book_id,
13+ "title": title,
14+ "author": author,
15+ "price": price
16+ })
17+ print("Book added successfully!\n")
18+
19+
20+ def view_books():
21+ if not books:
22+ print("No books available.\n")
23+ return
24+
25+ print("\n--- Book List ---")
26+ for book in books:
27+ print(f"ID: {book['id']}, Title: {book['title']}, Author: {book['author']}, Price: {book['price']}")
28+ print()
29+
30+
31+ def search_book():
32+ book_id = input("Enter Book ID to search: ")
33+ for book in books:
34+ if book["id"] == book_id:
35+ print("\nBook Found:")
36+ print(f"ID: {book['id']}, Title: {book['title']}, Author: {book['author']}, Price: {book['price']}\n")
37+ return
38+ print("Book not found!\n")
39+
40+
41+ def delete_book():
42+ book_id = input("Enter Book ID to delete: ")
43+ for book in books:
44+ if book["id"] == book_id:
45+ books.remove(book)
46+ print("Book deleted successfully!\n")
47+ return
48+ print("Book not found!\n")
49+
50+
51+ # Main Menu
52+ while True:
53+ print("===== Book Management System =====")
54+ print("1. Add Book")
55+ print("2. View Books")
56+ print("3. Search Book")
57+ print("4. Delete Book")
58+ print("5. Exit")
59+
60+ choice = input("Enter your choice: ")
61+
62+ if choice == "1":
63+ add_book()
64+ elif choice == "2":
65+ view_books()
66+ elif choice == "3":
67+ search_book()
68+ elif choice == "4":
69+ delete_book()
70+ elif choice == "5":
71+ print("Exiting program...")
72+ break
73+ else:
74+ print("Invalid choice! Try again.\n")
You can’t perform that action at this time.
0 commit comments