diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..6423e71 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,158 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "ce94ea53", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Order Statistics\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0%\n", + "\n", + "Updated Inventory:\n", + "t-shirt: 9\n", + "mug: 4\n", + "hat: 7\n", + "book: 3\n", + "keychain: 12\n" + ] + } + ], + "source": [ + "def get_inventory(products):\n", + " inventory = {}\n", + "\n", + " for product in products:\n", + " quantity = int(\n", + " input(f\"Enter quantity for {product}: \")\n", + " )\n", + " inventory[product] = quantity\n", + "\n", + " return inventory\n", + "\n", + "\n", + "def get_customer_orders(products):\n", + " customer_orders = set()\n", + "\n", + " while True:\n", + "\n", + " order = input(\n", + " \"Enter a product to order: \"\n", + " )\n", + "\n", + " if order in products:\n", + " customer_orders.add(order)\n", + "\n", + " another_product = input(\n", + " \"Do you want to add another product? (yes/no): \"\n", + " )\n", + "\n", + " if another_product.lower() == \"no\":\n", + " break\n", + "\n", + " return customer_orders\n", + "\n", + "\n", + "def update_inventory(inventory, customer_orders):\n", + "\n", + " for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + " return inventory\n", + "\n", + "\n", + "def calculate_order_statistics(\n", + " customer_orders,\n", + " products\n", + "):\n", + "\n", + " total_products_ordered = len(\n", + " customer_orders\n", + " )\n", + "\n", + " percentage_ordered = (\n", + " total_products_ordered\n", + " / len(products)\n", + " ) * 100\n", + "\n", + " return (\n", + " total_products_ordered,\n", + " percentage_ordered\n", + " )\n", + "\n", + "\n", + "def print_order_statistics(\n", + " order_statistics\n", + "):\n", + "\n", + " print(\"\\nOrder Statistics\")\n", + " print(\n", + " f\"Total Products Ordered: {order_statistics[0]}\"\n", + " )\n", + " print(\n", + " f\"Percentage of Products Ordered: {order_statistics[1]}%\"\n", + " )\n", + "\n", + "\n", + "def print_updated_inventory(\n", + " inventory\n", + "):\n", + "\n", + " print(\"\\nUpdated Inventory:\")\n", + "\n", + " for product, quantity in inventory.items():\n", + " print(\n", + " f\"{product}: {quantity}\"\n", + " )\n", + "\n", + "\n", + "products = [\n", + " \"t-shirt\",\n", + " \"mug\",\n", + " \"hat\",\n", + " \"book\",\n", + " \"keychain\"\n", + "]\n", + "\n", + "inventory = get_inventory(products)\n", + "\n", + "customer_orders = get_customer_orders(\n", + " products\n", + ")\n", + "\n", + "order_statistics = (\n", + " calculate_order_statistics(\n", + " customer_orders,\n", + " products\n", + " )\n", + ")\n", + "\n", + "inventory = update_inventory(\n", + " inventory,\n", + " customer_orders\n", + ")\n", + "\n", + "print_order_statistics(\n", + " order_statistics\n", + ")\n", + "\n", + "print_updated_inventory(\n", + " inventory\n", + ")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -61,7 +208,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4,