From 98ee2545556834eea420d27c99dba5934511b5e9 Mon Sep 17 00:00:00 2001 From: ghv29 Date: Sun, 18 Jan 2026 19:11:27 +0100 Subject: [PATCH] lab done --- lab-python-functions.ipynb | 112 ++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..2a99259 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,119 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "664593e3", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Products in customer orders: {'keychain', 'book', 'mug', 'hat'}\n", + "t-shirt, Quantity Left: 5\n", + "mug, Quantity Left: 5\n", + "hat, Quantity Left: 6\n", + "book, Quantity Left: 5\n", + "keychain, Quantity Left: 4\n", + "Order Statistics\n", + "Total Products Ordered: 4\n", + "Percentage of Products Ordered: 80.0 %\n" + ] + } + ], + "source": [ + "#1 \n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "#2\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for item in products:\n", + " quantity = int(input(f\"Enter the number of {item} available: \"))\n", + " inventory[item] = quantity\n", + " return inventory\n", + "#3\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + "\n", + " while True:\n", + " product = input(\"Enter the product name: \").lower()\n", + " \n", + " if product in products:\n", + " customer_orders.add(product) \n", + " else:\n", + " print(\"Invalid product. Please choose from:\", products)\n", + " \n", + " while True:\n", + " add_more = input(\"Do you want to order another product? (yes/no): \").lower()\n", + " if add_more in (\"yes\", \"no\"):\n", + " break\n", + " print(\"Please answer in 'yes' or 'no'.\")\n", + " if add_more == \"no\":\n", + " break\n", + " print(\"Products in customer orders:\", customer_orders)\n", + " return customer_orders\n", + "\n", + "\n", + "#4\n", + "def update_inventory(inventory,customer_orders):\n", + " for product_name in customer_orders:\n", + " if product_name in inventory:\n", + " inventory[product_name] -= 1\n", + " for item in products:\n", + " print(f\"{item}, Quantity Left: {inventory[item]}\") \n", + " return inventory\n", + "\n", + "#5\n", + "def calculate_order_statistics(customer_orders,products):\n", + " total_products_ordered = len(customer_orders)\n", + " percentage_ordered = (total_products_ordered / len(products)) * 100\n", + " order_status = (total_products_ordered, percentage_ordered)\n", + " return order_status\n", + "#6\n", + "def print_order_statistics(order_statistics):\n", + " print(\"Order Statistics\")\n", + " print(\"Total Products Ordered:\", order_statistics[0])\n", + " print(\"Percentage of Products Ordered:\", order_statistics[1], \"%\")\n", + "#7\n", + "def print_updated_inventory(inventory):\n", + " print(\"Updated Inventory:\")\n", + " for item, qty in inventory.items():\n", + " print(f\"{item}: {qty}\")\n", + "\n", + "inventory = initialize_inventory(products)\n", + "\n", + "customer_orders = get_customer_orders()\n", + "\n", + "inventory = update_inventory(inventory,customer_orders)\n", + "\n", + "order_statistics = calculate_order_statistics(customer_orders,products)\n", + "\n", + "print_order_statistics(order_statistics)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b2271b00", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "80b89dcf", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -61,7 +169,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.2" } }, "nbformat": 4,