From 7f448bdb09fab4b3d391b30ecebccd664fd968aa Mon Sep 17 00:00:00 2001 From: arnaumatasfont-keky Date: Tue, 14 Apr 2026 16:45:38 +0200 Subject: [PATCH] Update lab-python-functions.ipynb --- lab-python-functions.ipynb | 132 ++++++++++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 2 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..7dece7d 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,139 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "0dfffe53", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "776d9c01", + "metadata": {}, + "outputs": [], + "source": [ + "def get_costumers_orders():\n", + " costumers_order = set()\n", + " \n", + " add_product = \"yes\"\n", + " while add_product.lower() == \"yes\":\n", + " product = input(\"Enter the product name (t-shirt/pants/shoes/jacket): \").lower()\n", + " costumers_order.add(product)\n", + " add_product = input(\"Do you want to add another product? (yes/no): \").lower()\n", + " return costumers_order" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "102af78d", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventory(costumers_order, inventory):\n", + " for product in costumers_order:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "d3081ce7", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(costumers_order, products):\n", + " total_products_ordered = len(costumers_order)\n", + " percentage = (total_products_ordered / len(products)) * 100\n", + " return total_products_ordered, percentage\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "ed29f324", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " total_products_ordered, percentage = order_statistics\n", + " \n", + " print(\"\\nOrder Statistics:\")\n", + " print(f\"Total products ordered: {total_products_ordered}\")\n", + " print(f\"Percentage of unique products ordered: {percentage:.2f}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "e6b3172c", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory(inventory):\n", + " print(\"\\nUpdated Inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product.capitalize()}: {quantity} units left\")" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "585cb887", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Order Statistics:\n", + "Total products ordered: 3\n", + "Percentage of unique products ordered: 75.00%\n", + "\n", + "Updated Inventory:\n", + "T-shirt: 9 units left\n", + "Pants: 12 units left\n", + "Shoes: 7 units left\n", + "Jacket: 5 units left\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"pants\", \"shoes\", \"jacket\"]\n", + "\n", + "inventory = initialize_inventory(products)\n", + "\n", + "costumers_order = get_costumers_orders()\n", + "\n", + "inventory = update_inventory(costumers_order, inventory)\n", + "\n", + "order_statistics = calculate_order_statistics(costumers_order, products)\n", + "\n", + "print_order_statistics(order_statistics)\n", + "\n", + "print_updated_inventory(inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": ".venv", "language": "python", "name": "python3" }, @@ -61,7 +189,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.3" } }, "nbformat": 4,