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
70 changes: 70 additions & 0 deletions clothes bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
def begin_chatbot():

print("Hello! I am you virutal helper for returns and exchanges.")

def start_return():
print("\n--- RETURN PROCESS ---")
print("Okay, let's help you return your item.")
print("Choose the reason below:")
print("A. Damaged or defective")
print("B. Doesn't fit")
print("C. Changed my mind / Not what I expected")
print("D. Return to Main Menu")

reason = input("Enter your reason (A-D): ").strip().upper()

if reason in ['A', 'B', 'C']:
print(f"\nGot it — you chose '{reason}'. Starting your return authorization...")
print("Check your email — you'll get a pre-paid return label shortly.")
print("Once we receive and inspect the item, we'll process your refund or store credit.")
elif reason == 'D':
return
else:
print("\nThat doesn't seem like a valid choice. Let's go back to the menu.")

def start_exchange():

print("\n--- EXCHANGE PROCESS ---")
print("We'll help you swap your item for a different size or color.")
print("(You'll need your Order Number for this step.)")

id_number = input("Enter your Order Number (e.g., ORD-12345): ").strip()

if len(id_number) < 5:
print("\nThat doesn't seem like a valid order number. Try again from the main menu.")
return
else:
print(f"\nSearching for order '{id_number}'...")
print("Order found")
print("We'll guide you through picking a new size/color.")
print("A new shipping label and replacement item will be sent soon.")

def show_policiy():

print("\n--- RETURN & EXCHANGE POLICY ---")
print(" Returns accepted within 30 days of delivery.")
print(" Items must be unworn, unwashed, and have all original tags.")
print(" Final Sale items are non-returnable/non-exchangeable.")
print(" Exchanges are free; returns have a small $5 shipping fee.")
print("\nFor the full policy, check our website.")

# Main program loop
while True:
print("\n ---Main Menu---")
print("1. Start a return")
print("2. Start an exchange")
print("3. View 'Return and Exchange Policy'")
print("4. Exit")

menu_choice = input("Please enter your choice (1-4): ").strip()
if menu_choice == '1':
start_return()
elif menu_choice == '2':
start_exchange()
elif menu_choice == '3':
show_policiy()
elif menu_choice == '4':
print("\nThank you for using the Clothes shopping virtual assitant")
break
else:
print("\nTry typing a number between 1 and 4")
293 changes: 293 additions & 0 deletions librarian bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
from datetime import datetime, timedelta
from typing import List, Dict, Optional

library_books = [
{
"id": "B1",
"title": "The Lightning Thief",
"author": "Rick Riordan",
"genre": "Fantasy",
"available": True,
"due_date": None,
"checkouts": 2
},
{
"id": "B2",
"title": "To Kill a Mockingbird",
"author": "Harper Lee",
"genre": "Historical",
"available": False,
"due_date": "2024-01-15",
"checkouts": 5
},
{
"id": "B3",
"title": "1984",
"author": "George Orwell",
"genre": "Dystopian",
"available": True,
"due_date": None,
"checkouts": 8
},
{
"id": "B4",
"title": "Pride and Prejudice",
"author": "Jane Austen",
"genre": "Romance",
"available": False,
"due_date": "2025-12-01",
"checkouts": 1
},
{
"id": "B5",
"title": "Sapiens: A Brief History of Humankind",
"author": "Yuval Noah Harari",
"genre": "Non-Fiction",
"available": True,
"due_date": None,
"checkouts": 10
},
{
"id": "B6",
"title": "A Game of Thrones",
"author": "George R. R. Martin",
"genre": "Fantasy",
"available": True,
"due_date": None,
"checkouts": 3
}
]

class Book:
def __init__(self, book_data: Dict):
self.id = book_data["id"]
self.title = book_data["title"]
self.author = book_data["author"]
self.genre = book_data["genre"]
self.available = book_data["available"]
self.due_date = self.parse_date(book_data["due_date"])
self.checkouts = book_data["checkouts"]

def parse_date(self, date_str):
if date_str is not None:
try:
return datetime.strptime(date_str, "%Y-%m-%d")
except:
print(f"Warning: Could not parse date {date_str}")
return None
return None

def show_book_info(self, show_details=True):
if self.available:
status_text = "Available"
else:
if self.due_date:
due_formatted = self.due_date.strftime('%Y-%m-%d')
status_text = f"Checked out (Due: {due_formatted})"
else:
status_text = "Checked out (Due: N/A)"

if show_details:
print(f" ID: {self.id:<3} | Title: {self.title:<30} | Author: {self.author:<20} | Genre: {self.genre:<12} | Status: {status_text}")
else:
print(f" ID: {self.id:<3} | Title: {self.title:<30} | Author: {self.author:<20}")

def checkout_book(self):
if self.available == True:
self.available = False
today = datetime.now()
self.due_date = today + timedelta(weeks=2)
self.checkouts = self.checkouts + 1
return True
else:
return False

def return_book(self):
self.available = True
self.due_date = None

def check_if_overdue(self):
if self.available == False and self.due_date is not None:
current_time = datetime.now()
if current_time > self.due_date:
return True
return False

book_inventory = []
for book_data in library_books:
new_book = Book(book_data)
book_inventory.append(new_book)

def find_book_by_id(book_id):
book_id_lower = book_id.lower()
for book in book_inventory:
if book.id.lower() == book_id_lower:
return book
return None

def show_available_books():
print("\n--- Available Books ---")
available_books = []

for book in book_inventory:
if book.available:
available_books.append(book)

if len(available_books) == 0:
print("No books are currently available.")
else:
for book in available_books:
book.show_book_info(show_details=False)

print("-------------------------")

def search_for_books(search_term):
if not search_term or search_term.strip() == "":
print("Search term cannot be empty.")
return

search_lower = search_term.lower().strip()
matching_books = []

for book in book_inventory:
author_match = search_lower in book.author.lower()
genre_match = search_lower in book.genre.lower()

if author_match or genre_match:
matching_books.append(book)

print(f"\n--- Search Results for '{search_term}' ({len(matching_books)} found) ---")

if len(matching_books) == 0:
print("No books found matching the author or genre.")
else:
for book in matching_books:
book.show_book_info(show_details=True)

print("---------------------------------------------------------------")

def checkout_book(book_id):
target_book = find_book_by_id(book_id)

if target_book is None:
print(f"\nError: Book with ID '{book_id}' not found.")
return

checkout_success = target_book.checkout_book()

if checkout_success:
due_date_str = target_book.due_date.strftime('%Y-%m-%d')
print(f"\nSuccess: '{target_book.title}' (ID: {target_book.id}) has been checked out.")
print(f" It is due on: {due_date_str}.")
else:
if target_book.due_date:
due_date_str = target_book.due_date.strftime('%Y-%m-%d')
else:
due_date_str = "N/A"
print(f"\nNote: '{target_book.title}' is already checked out.")
print(f" It is due on: {due_date_str}.")

def return_book(book_id):
target_book = find_book_by_id(book_id)

if target_book is None:
print(f"\nError: Book with ID '{book_id}' not found.")
return

if target_book.available == True:
print(f"\nNote: '{target_book.title}' is already marked as available.")
return

target_book.return_book()
print(f"\nSuccess: '{target_book.title}' (ID: {target_book.id}) has been returned and is now available.")

def show_overdue_books():
print("\n--- Overdue Books ---")
overdue_books = []

for book in book_inventory:
if book.check_if_overdue():
overdue_books.append(book)

if len(overdue_books) == 0:
print("No books are currently overdue. Keep up the good work!")
else:
for book in overdue_books:
if book.due_date:
due_str = book.due_date.strftime('%Y-%m-%d')
else:
due_str = "N/A"
print(f" ID: {book.id}, Title: {book.title}, Author: {book.author}, **OVERDUE since: {due_str}**")

print("---------------------------")

def show_most_popular_books():
print("\n--- Top 3 Most Checked-Out Books ---")

if len(book_inventory) == 0:
print("No books in inventory.")
print("--------------------------------------")
return

sorted_books = sorted(book_inventory, key=lambda x: x.checkouts, reverse=True)

top_books = sorted_books[:3]

counter = 1
for book in top_books:
print(f" {counter}. Title: {book.title:<30} | Checkouts: {book.checkouts}")
counter += 1

print("--------------------------------------")

def print_menu():
print("\n\n*** Library Manager Menu ***")
print("1. View Available Books")
print("2. Search by Author or Genre")
print("3. Checkout a Book (by ID)")
print("4. Return a Book (by ID)")
print("5. View Overdue Books")
print("6. View Top 3 Most Checked-Out Books")
print("7. Exit")
print("*******************************")

def main():
print("Welcome to the Library Inventory and Checkout Manager!")

while True:
print_menu()
user_choice = input("Enter your choice (1-7): ").strip()

if user_choice == '1':
show_available_books()

elif user_choice == '2':
search_input = input("Enter author or genre search term: ").strip()
if search_input:
search_for_books(search_input)

elif user_choice == '3':
book_id_input = input("Enter the **Book ID** to checkout (e.g., B1): ").strip()
if book_id_input:
checkout_book(book_id_input)

elif user_choice == '4':
book_id_input = input("Enter the **Book ID** to return (e.g., B2): ").strip()
if book_id_input:
return_book(book_id_input)

elif user_choice == '5':
show_overdue_books()

elif user_choice == '6':
show_most_popular_books()

elif user_choice == '7':
print("Thank you for using the Library Manager. Goodbye!")
break

else:
print("Invalid choice. Please enter a number between 1 and 7.")

if __name__ == "__main__":
main()
27 changes: 0 additions & 27 deletions main.py

This file was deleted.