From 2da1029099cb8ebf0f24a5f4467f6d1eee599679 Mon Sep 17 00:00:00 2001 From: Pollob Date: Wed, 8 Apr 2026 02:00:19 +0200 Subject: [PATCH] Prob Solved --- lab-python-functions.ipynb | 100 ++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..8dca5dd 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,107 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f0c9babe", + "metadata": {}, + "outputs": [], + "source": [ + "##Problem 1\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + "\n", + " for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + "\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "e2d27bd0", + "metadata": {}, + "outputs": [], + "source": [ + "##Problem 2\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + "\n", + " while True:\n", + " product = input(\"Enter the product name: \").lower()\n", + " customer_orders.add(product)\n", + "\n", + " choice = input(\"Do you want to add another product? (yes/no): \").lower()\n", + "\n", + " if choice == \"yes\":\n", + " continue\n", + " elif choice == \"no\":\n", + " break\n", + " else:\n", + " print(\"Invalid input. Stopping order entry.\")\n", + " break\n", + "\n", + " return customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "ff25cfe7", + "metadata": {}, + "outputs": [], + "source": [ + "### problem 3\n", + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + " else:\n", + " print(f\"Sorry, {product} is out of stock.\")\n", + " else:\n", + " print(f\"{product} is not in the inventory.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "e01eb2db", + "metadata": {}, + "outputs": [], + "source": [ + "##problem 3\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", + "\n", + " return total_products_ordered, percentage_ordered" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "0af139bf", + "metadata": {}, + "outputs": [], + "source": [ + "##problem 5\n", + "def print_order_statistics(order_statistics):\n", + " total_products_ordered, percentage_ordered = order_statistics\n", + "\n", + " print(\"\\nOrder Statistics\")\n", + " print(f\"Total products ordered: {total_products_ordered}\")\n", + " print(f\"Percentage of products ordered: {percentage_ordered:.2f}%\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -61,7 +157,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,