diff --git a/Lab_Functions.ipynb b/Lab_Functions.ipynb new file mode 100644 index 0000000..c272cd7 --- /dev/null +++ b/Lab_Functions.ipynb @@ -0,0 +1,144 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "qBnDdit6jv6n", + "outputId": "67f5a866-3398-474a-e125-afec81dd3874" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Input quantity for each product:\n" + ] + } + ], + "source": [ + "#Initialize Inventory\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " print(\"Input quantity for each product:\")\n", + " for product in products:\n", + " quantity = int(input(f\"{product.capitalize()}: \"))\n", + " inventory[product] = quantity\n", + " return inventory\n", + "\n", + "\n", + "#Get Customer Orders\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + "\n", + " while True:\n", + " order = input(\"\\nEnter the name of a product a customer wants to order: \").strip().lower()\n", + "\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " print(f\"'{order}' added to order.\")\n", + " else:\n", + " print(\"Product not available. Please choose a different product.\")\n", + " continue\n", + "\n", + " another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " if another != \"yes\":\n", + " break\n", + "\n", + " return customer_orders\n", + "\n", + "#Update Inventory\n", + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + " else:\n", + " print(f\"'{product}' is out of stock\")\n", + "\n", + "\n", + "\n", + "# Calculate Order Statistics\n", + "\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + " total_products_available = len(products)\n", + " percentage_ordered = (total_products_ordered / total_products_available) * 100\n", + "\n", + " return total_products_ordered, percentage_ordered\n", + "\n", + "\n", + "\n", + "# Print Order Statistics\n", + "\n", + "def print_order_statistics(order_statistics):\n", + " print(\"\\nOrder Statistics:\")\n", + " print(f\"Total Products Ordered: {order_statistics[0]}\")\n", + " print(f\"Percentage of Products Ordered: {order_statistics[1]:.2f}%\")\n", + "\n", + "\n", + "\n", + "#Print Updated Inventory\n", + "\n", + "def print_updated_inventory(inventory):\n", + " print(\"\\nUpdated Inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product.capitalize()}: {quantity}\")\n", + "\n", + "\n", + "\n", + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# Initialize inventory\n", + "inventory = initialize_inventory(products)\n", + "\n", + "# Get customer orders\n", + "customer_orders = get_customer_orders()\n", + "\n", + "# Display customer orders\n", + "print(\"\\nCustomer Ordered Products:\")\n", + "for product in customer_orders:\n", + " print(product.capitalize())\n", + "\n", + "# Calculate statistics\n", + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "\n", + "# Print statistics\n", + "print_order_statistics(order_statistics)\n", + "\n", + "# Update inventory\n", + "update_inventory(customer_orders, inventory)\n", + "\n", + "# Print inventory\n", + "print_updated_inventory(inventory)\n" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "base", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}