From 74ca3f43e8751ad93bdb5b0113f6626461f2d312 Mon Sep 17 00:00:00 2001 From: AnaP2020 Date: Sun, 10 May 2026 15:10:26 +0100 Subject: [PATCH] Lab done --- lab-python-data-structures.ipynb | 82 +++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 11 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..f64bad1e 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -1,14 +1,5 @@ { "cells": [ - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "# Lab | Data Structures " - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -50,11 +41,80 @@ "\n", "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory: {'t-shirt': 19, 'mug': 20, 'hat': 18, 'book': 5, 'keychain': 4}\n", + "Customer Orders: {' book', 'mug', ' hat'}\n", + "Order Statistics:\n", + "Total products ordered: 3\n", + "Percentage of products ordered: 4.55%\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "quantity_tshirt = int(input(\"Enter the quantity for t-shirt: \"))\n", + "quantity_mug = int(input(\"Enter the quantity for mug: \"))\n", + "quantity_hat = int(input(\"Enter the quantity for hat: \"))\n", + "quantity_book = int(input(\"Enter the quantity for book: \"))\n", + "quantity_keychain = int(input(\"Enter the quantity for keychain: \"))\n", + "inventory[\"t-shirt\"] = quantity_tshirt\n", + "inventory[\"mug\"] = quantity_mug\n", + "inventory[\"hat\"] = quantity_hat\n", + "inventory[\"book\"] = quantity_book\n", + "inventory[\"keychain\"] = quantity_keychain\n", + "print(f\"Inventory: {inventory}\")\n", + "customer_orders = set()\n", + "customer_wants_to_order = input(\"Enter the 3 products you want to order from the list (separated by commas): \")\n", + "customer_wants_to_order_list = customer_wants_to_order.split(\",\")\n", + "customer_orders.update(customer_wants_to_order_list)\n", + "print(f\"Customer Orders: {customer_orders}\")\n", + "total_products_ordered = len(customer_orders)\n", + "total_products_available = sum(inventory.values())\n", + "order_percentage = (total_products_ordered/total_products_available) * 100\n", + "order_status = (total_products_ordered, order_percentage)\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total products ordered: {order_status[0]}\")\n", + "print(f\"Percentage of products ordered: {order_status[1]:.2f}%\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total stock after the order for book: 18\n", + "Total stock after the order for hat: 14\n", + "Total stock after the order for mug: 17\n" + ] + } + ], + "source": [ + "inventory[\"book\"] = inventory[\"book\"] - 1\n", + "inventory[\"hat\"] = inventory[\"hat\"] - 1\n", + "inventory[\"mug\"] = inventory[\"mug\"] - 1\n", + "print(f\"Total stock after the order for book: {inventory['book']}\")\n", + "print(f\"Total stock after the order for hat: {inventory['hat']}\")\n", + "print(f\"Total stock after the order for mug: {inventory['mug']}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +128,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,