From 1c82a41e6be94e5406fcd8f9e547c18a9a8e267f Mon Sep 17 00:00:00 2001 From: Selaseyjr Date: Wed, 21 Jan 2026 17:14:15 +0100 Subject: [PATCH] pythonlab done --- lab-python-functions.ipynb | 154 ++++++++++++++++++++++++++++++++++++- 1 file changed, 152 insertions(+), 2 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..5645caf 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,161 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "67a0dc1d", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products):\n", + " inventory={}" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "28232a85", + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (1415910399.py, line 9)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[12]\u001b[39m\u001b[32m, line 9\u001b[39m\n\u001b[31m \u001b[39m\u001b[31minitialize_inventory(products):\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m invalid syntax\n" + ] + } + ], + "source": [ + "for product in products:\n", + " print (products)\n", + " quantity = int(input(f\"Enter quantity for {product}: \"))\n", + " print(quantity)\n", + " inventory[product] = quantity\n", + "\n", + "return inventory\n", + "\n", + "initialize_inventory(products):" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "086d3bfa", + "metadata": {}, + "outputs": [], + "source": [ + "def get_customer_orders():\n", + " customer_orders = set()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "69b1a224", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'customer_orders' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[7]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[32m 2\u001b[39m product_name = \u001b[38;5;28minput\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mEnter a product name: \u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m \u001b[43mcustomer_orders\u001b[49m.add(product_name)\n\u001b[32m 5\u001b[39m another = \u001b[38;5;28minput\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mDo you want to add another product? (yes/no): \u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m 6\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m another != \u001b[33m\"\u001b[39m\u001b[33myes\u001b[39m\u001b[33m\"\u001b[39m:\n", + "\u001b[31mNameError\u001b[39m: name 'customer_orders' is not defined" + ] + } + ], + "source": [ + "while True:\n", + " product_name = input(\"Enter a product name: \")\n", + " customer_orders.add(product_name)\n", + "\n", + " another = input(\"Do you want to add another product? (yes/no): \")\n", + " if another != \"yes\":\n", + " break\n", + "\n", + "return customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "02a5d432", + "metadata": {}, + "outputs": [], + "source": [ + "inventory = initialize_inventory(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "d1a7b642", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "28980680", + "metadata": {}, + "outputs": [], + "source": [ + "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\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "130920a0", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " print(\"\\nOrder Statistics:\")\n", + " print(f\"Total Products Ordered: {order_statistics[0]}\")\n", + " print(f\"Percentage of Products Ordered: {order_statistics[1]}%\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "f7564cdd", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory(inventory):\n", + " print(\"\\nUpdated Inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "82788b85", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -61,7 +211,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.2" } }, "nbformat": 4,