Back to projects
PythonBeginner–Intermediate1–2 sessions
Library Book Manager
Students model a tiny school library using only Python lists and functions. It is an approachable way to connect code to a familiar school activity.
Starter code
Read it. Run it. Change it.
Save the code below as library_manager.py. The example is intentionally small enough for a student to explain line by line before adding new features.
library_manager.pyPython
books = ["The Jungle Book", "Wings of Fire", "The Blue Umbrella"]
def show_books():
print("\nAvailable books:")
for book in books:
print("-", book)
while True:
print("\n1. View books")
print("2. Borrow a book")
print("3. Return a book")
print("4. Exit")
choice = input("Choose an option: ")
if choice == "1":
show_books()
elif choice == "2":
title = input("Book title: ")
if title in books:
books.remove(title)
print("You borrowed", title)
else:
print("That book is not available.")
elif choice == "3":
title = input("Book title to return: ")
books.append(title)
print("Returned", title)
elif choice == "4":
print("Goodbye!")
break
else:
print("Please choose 1, 2, 3, or 4.")How to run it on a laptop
- 1. Install Python 3 if it is not already available.
- 2. Open IDLE, Thonny, VS Code, or any simple text editor.
- 3. Copy the code into a new file named
library_manager.py. - 4. Run the file. No internet connection, database, or server is required.
Build it step by step
1
Store books
Start with a list representing the books currently available.
2
Build a menu
Let the user choose whether to view, borrow, return, or exit.
3
Change the list
Remove a borrowed book and add a returned book.
4
Repeat
Use a while loop so the program keeps running until the user exits.
Make it your own
- Prevent the same returned book from being added twice.
- Keep a second list of borrowed books.
- Add a search option that checks whether a title is available.