From a402da6c7430ed5da53437637cf4108332a5e752 Mon Sep 17 00:00:00 2001 From: malikabaguari Date: Sat, 20 Jun 2026 13:04:39 +0200 Subject: [PATCH] Add files via upload --- lab-python-data-structures.ipynb | 254 ++++++++++++++++++++++--------- 1 file changed, 180 insertions(+), 74 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..a138d549 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -1,76 +1,182 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "# Lab | Data Structures " - ] + "metadata": { + "kernelspec": { + "name": "python", + "display_name": "Python (Pyodide)", + "language": "python" + }, + "language_info": { + "codemirror_mode": { + "name": "python", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8" + } }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Exercise: Managing Customer Orders\n", - "\n", - "As part of a business venture, you are starting an online store that sells various products. To ensure smooth operations, you need to develop a program that manages customer orders and inventory.\n", - "\n", - "Follow the steps below to complete the exercise:\n", - "\n", - "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", - "\n", - "2. Create an empty dictionary called `inventory`.\n", - "\n", - "3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n", - "\n", - "4. Create an empty set called `customer_orders`.\n", - "\n", - "5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set.\n", - "\n", - "6. Print the products in the `customer_orders` set.\n", - "\n", - "7. Calculate the following order statistics:\n", - " - Total Products Ordered: The total number of products in the `customer_orders` set.\n", - " - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", - " \n", - " Store these statistics in a tuple called `order_status`.\n", - "\n", - "8. Print the order statistics using the following format:\n", - " ```\n", - " Order Statistics:\n", - " Total Products Ordered: \n", - " Percentage of Products Ordered: % \n", - " ```\n", - "\n", - "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", - "\n", - "10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", - "\n", - "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.13" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} + "nbformat_minor": 5, + "nbformat": 4, + "cells": [ + { + "id": "23ee3234-fea8-435d-9f99-ee68df89ff29", + "cell_type": "code", + "source": "#1 Define a list called products\nproducts = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 17 + }, + { + "id": "9c7db885-7886-4989-a7fc-834ad850f533", + "cell_type": "code", + "source": "#2.Create an empty dictionary called inventory\ninventory_dict= {}\n", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 18 + }, + { + "id": "fb0adb26-7e6f-43a2-8b0f-f5decc4b0db0", + "cell_type": "code", + "source": "#3.Ask the user to input the quantity of each product available in the inventory\nfor product in products : \n quantity = input(\"How many do you need? : \") \n quantity = int(quantity)\n inventory_dict [ product] = quantity\n\nprint(inventory_dict)\n ", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdin", + "text": "How many do you need? : 2\nHow many do you need? : 3\nHow many do you need? : 4\nHow many do you need? : 5\nHow many do you need? : 6\n" + }, + { + "name": "stdout", + "output_type": "stream", + "text": "{'t-shirt': 2, 'mug': 3, 'hat': 4, 'book': 5, 'keychain': 6}\n" + } + ], + "execution_count": 19 + }, + { + "id": "e6625df4-d2c5-4c49-9c53-8aaf46ad156a", + "cell_type": "code", + "source": "#4.Create an empty set called customer_orders\ncustomer_orders = set()\n\n#5 Ask the user to input the name of three products\nfor p in range(3): \n product = input(\"select the product: \") \n customer_orders.add(product)\n\n \n\n\n\n", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdin", + "text": "select the product: hat\nselect the product: book\nselect the product: mug\n" + } + ], + "execution_count": 21 + }, + { + "id": "5a259adc-ec08-4c36-8479-0601c567bb7e", + "cell_type": "code", + "source": "#6 Print the products in the customer_orders set\nprint(customer_orders)\n", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "{'hat', 'mug', 'book'}\n" + } + ], + "execution_count": 22 + }, + { + "id": "d3b96a8b-0b78-4bf4-bcfe-9f40d88be3dc", + "cell_type": "code", + "source": "#7 Calculate the statistics:\n\ntotal_product_ordered = len(customer_orders)\nrate_product_ordered = (total_product_ordered/len(products))*100\norder_status = (total_product_ordered, rate_product_ordered)\nprint(order_status)", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "(3, 60.0)\n" + } + ], + "execution_count": 7 + }, + { + "id": "c6a8af5d-fc46-4ef6-93a2-669e61c2a727", + "cell_type": "code", + "source": "#8 Print the order statistics\n\nprint(\"\\nOrder Statistics:\")\nprint(f\"Total Products Ordered: {order_status[0]}\")\nprint(f\"Percentage of Products Ordered: {order_status[1]}%\")", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "\nOrder Statistics:\nTotal Products Ordered: 3\nPercentage of Products Ordered: 60.0%\n" + } + ], + "execution_count": 23 + }, + { + "id": "cf99365e-0695-4a2f-94cc-7a2b13941360", + "cell_type": "code", + "source": "#9 Update the inventory by subtracting 1\nfor x,y in inventory_dict.items():\n inventory_dict[x] = y - 1\n", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 24 + }, + { + "id": "2904eff9-2f75-40c9-8787-02698000d391", + "cell_type": "code", + "source": "print(inventory_dict)\n", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n" + } + ], + "execution_count": 25 + }, + { + "id": "96f42746-3e6d-471f-ab49-10d5ee6d645f", + "cell_type": "code", + "source": "# 10 Print the updated inventory\nfor x,y in inventory_dict.items():\n print(x ,\":\", y)", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "t-shirt : 1\nmug : 2\nhat : 3\nbook : 4\nkeychain : 5\n" + } + ], + "execution_count": 26 + }, + { + "id": "5b99fdf1-33bd-4038-9751-3794bb13728b", + "cell_type": "code", + "source": "", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": null + } + ] +} \ No newline at end of file