From bfec283f88691768a77721b5ea3bb419796ea18f Mon Sep 17 00:00:00 2001 From: Radhika Date: Tue, 20 Jan 2026 10:38:10 +0100 Subject: [PATCH] lab3 --- lab-python-functions.ipynb | 90 +++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..5310bc7 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,97 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "ee6b45e4", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products):\n", + " inventory = {}\n", + "\n", + " for product in products:\n", + " quantity = int(input(\"Enter quantity for product:\"))\n", + " inventory[product] = quantity\n", + "\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "31e6e5cc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'keychain'}\n" + ] + } + ], + "source": [ + "def get_customer_orders():\n", + " customer_orders = set()\n", + "\n", + " while True:\n", + " product = input(\"Enter product name: \")\n", + " customer_orders.add(product)\n", + "\n", + " choice = input(\"Do you want to enter another product? (yes/no): \")\n", + "\n", + " if choice.lower() == \"no\":\n", + " break\n", + "\n", + " return customer_orders\n", + "orders = get_customer_orders()\n", + "print(orders)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "a53e7adb", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "inventory={'t-shirt': 5, 'mug': 4, 'hat': 3, 'book': 2, 'keychain': 1}\n", + "customer_orders={'hat','keychain'}\n", + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + " print(update_inventory)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b5222c71", + "metadata": {}, + "outputs": [], + "source": [ + "customer_order = {'hat', 'keychain'}\n", + "products = {'t-shirt', 'mug', 'hat', 'book', 'keychain'}\n", + "\n", + "def calculate_order_statistics(customer_order, products):\n", + " total_product_ordered = len(customer_order)\n", + " percentage_ordered = (total_product_ordered / len(products)) * 100\n", + " return total_product_ordered, percentage_ordered\n", + "print(total_product_ordered)\n", + "print(percentage_ordered)\n", + " " + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -61,7 +147,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,