Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions submissions/caaif43/project final/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# Library Management System (CLI)

A small command-line Library Management System built with Python 3.10+.

This project demonstrates the core concepts covered in Sections 1–6 of the Python Bootcamp, including:

* Comments
* `print()` and `input()`
* Conditional statements (`if`, `elif`, `else`)
* Lists and loops
* Functions and `main()`
* File handling (UTF-8)
* Error handling with `try` / `except`
* Object-Oriented Programming (OOP)
* `@dataclass`
* `__str__()` methods
* Composition

---

## Run the Project

```bash
cd 07_final_project_library_management_system
python main.py
```

---

## Project Structure

```text
07_final_project_library_management_system/
├── main.py
├── models/
│ └── books.py
├── utils/
│ └── storage.py
├── data/
│ └── books.txt
└── README.md
```

---

## Features

The system allows a librarian to:

1. Add a new book
2. View all books
3. Remove a book
4. Search for a book by ID
5. Update book information
6. Save library data
7. Quit the application (automatically saves data)

---

## Book Information

Each book contains:

* Book ID
* Title
* Author
* Year Published

Example:

```text
ID: 101
Title: Python Basics
Author: Abdullahi hassan
Year: 2026
```

---

## Data Storage

All library data is stored in:

```text
data/books.txt
```

The file uses UTF-8 encoding and a simple pipe-separated format.

Example:

```text
# Library Database
id|title|author|year
101|Python Basics|Abdullahi|2026
```

### Notes

* Lines beginning with `#` are treated as comments.
* The header row is ignored when loading data.
* Data is automatically loaded when the application starts.
* Data is automatically saved when the application exits.

---

## Error Handling

The project uses `try` / `except` blocks to prevent crashes caused by invalid user input.

Examples:

* Entering text instead of a numeric ID
* Entering an invalid publication year
* Loading a missing data file

---

## OOP Concepts Used

### Book Class

Represents a single book in the library.

Responsibilities:

* Store book information
* Display formatted book details using `__str__()`

### Library Class

Represents the entire library collection.

Responsibilities:

* Store books in memory
* Add books
* Remove books
* Search books
* Manage library records

This demonstrates **composition**, where a `Library` object contains multiple `Book` objects.

---

## Technologies

* Python 3.10+
* Dataclasses
* File Handling
* UTF-8 Text Storage
* Command-Line Interface (CLI)

---

## Learning Objectives

After completing this project, students should be able to:

* Build a complete CLI application
* Organize code into modules
* Work with classes and objects
* Read and write files
* Handle user input safely
* Apply Python best practices
* Create maintainable project structures

---

## Author

Abdullahi Hassan Shire

Python Bootcamp Final Project
Library Management System
38 changes: 38 additions & 0 deletions submissions/caaif43/project final/data/calo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
def add(a,b) :
return a+b
def subtract (a,b) :
return a - b
def multiply (a,b):
return a*b
def divide (a,b):
if b == 0:
return "eber lama qeybin karo. !"
return a/b


def main():
print("soo dhawow")
print("dooro mid:")
print("1. isku dar")
print("2. kala jarid")
print("3. isku dhufasho")
print("4. iskuqeybin")
while True:
doorsho = input ("dooro mid 1,2,3,4")
if doorsho in ['1','2','3','4']:
try:
num1 = float(input("gali number kowaad"))
num2 = float(input("gali number labaad"))
except ValueError:
print("fad;an kali number")
continue
if doorsho == '1':
print(f"numberka waa {add(num1,num2)}")
elif doorsho == '2':
print(f"numberka waa {subtract(num1,num2)}")
elif doorsho == '3':
print(f"numberka waa {multiply(num1,num2)}")
else:
if __name__("main"):
main()

4 changes: 4 additions & 0 deletions submissions/caaif43/project final/data/members.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Gym Members
id|member_name|membership_type
1|Ahmed|Premium
2|Asha|Standard
128 changes: 128 additions & 0 deletions submissions/caaif43/project final/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#_final_project_gym_management_system/main.py
from models.members import Member, Gym
from utils.storage import load_members, save_members


gym = Gym()
gym.members = load_members()


def add_member():
try:
member_id = int(input("Enter member ID: "))
except ValueError:
print("Invalid ID")
return

member_name = input("Enter member name: ")
membership_type = input("Enter membership type: ")

member = Member(member_id, member_name, membership_type)

gym.add_member(member)

print("Member added successfully")


def list_members():
if not gym.members:
print("No members found")
return

for member in gym.members:
print(member)


def search_member():
name = input("Enter member name: ")

member = gym.search_member(name)

if member:
print(member)
else:
print("Member not found")


def update_member():
try:
member_id = int(input("Enter member ID: "))
except ValueError:
print("Invalid ID")
return

member = gym.get_member_by_id(member_id)

if not member:
print("Member not found")
return

new_name = input("Enter new name: ")
new_type = input("Enter new membership type: ")

if new_name:
member.member_name = new_name

if new_type:
member.membership_type = new_type

print("Member updated successfully")


def remove_member():
try:
member_id = int(input("Enter member ID to remove: "))
except ValueError:
print("Invalid ID")
return

if gym.remove_member(member_id):
print("Member removed")
else:
print("Member not found")


def main():
while True:

print("\n===== GYM MENU =====")
print("1. Add Member")
print("2. List Members")
print("3. Search Member")
print("4. Update Member")
print("5. Remove Member")
print("6. Save")
print("7. Quit")

choice = input("Choose: ")

if choice == "1":
add_member()

elif choice == "2":
list_members()

elif choice == "3":
search_member()

elif choice == "4":
update_member()

elif choice == "5":
remove_member()

elif choice == "6":
save_members(gym.members)
print("Members saved")

elif choice == "7":
save_members(gym.members)
print("Goodbye")
break

else:
print("Invalid choice")


if __name__ == "__main__":
main()
Binary file not shown.
Loading
Loading