From 89d06f6cff3e50743e5d87b783c96e8a127c94d1 Mon Sep 17 00:00:00 2001 From: davherdel Date: Sat, 16 Aug 2025 15:06:06 +0100 Subject: [PATCH 1/2] Uploaded notebook --- lab-python-data-structures.ipynb | 95 ++++++++++++++++++++++++++++---- 1 file changed, 84 insertions(+), 11 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..4c5eb0dd 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,93 @@ "\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": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter available quantity for each product:\n", + "\n", + "Enter the name of 3 products to order:\n", + "That product is not in the list. Please choose from: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "\n", + "Customer ordered the following products:\n", + "- book\n", + "- mug\n", + "\n", + "Order Statistics:\n", + "Total Products Ordered: 2\n", + "Percentage of Products Ordered: 40.00%\n", + "\n", + "Updated Inventory:\n", + "T-shirt: 1111\n", + "Mug: 2221\n", + "Hat: 3333\n", + "Book: 4443\n", + "Keychain: 5555\n" + ] + } + ], + "source": [ + "# 1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "#2. Create an empty dictionary called `inventory`.\n", + "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", + "print(\"Enter available quantity for each product:\")\n", + "for product in products:\n", + " quantity = int(input(f\"{product.capitalize()}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "#4. Create an empty set called `customer_orders`.\n", + "customer_orders = set()\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", + "print(\"\\nEnter the name of 3 products to order:\")\n", + "for i in range(3):\n", + " order = input(f\"Product #{i+1}: \").strip().lower()\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " else:\n", + " print(\"That product is not in the list. Please choose from:\", products)\n", + "\n", + "#6. Print the products in the `customer_orders` set.\n", + "print(\"\\nCustomer ordered the following products:\")\n", + "for item in customer_orders:\n", + " print(\"-\", item)\n", + "\n", + "#7. Calculate the following order statistics:\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "#8. Print the order statistics using the desired format\n", + "print(\"\\nOrder Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n", + "\n", + "#9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", + "for item in customer_orders:\n", + " if inventory[item] > 0:\n", + " inventory[item] -= 1\n", + "\n", + "#10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "print(\"\\nUpdated Inventory:\")\n", + "for product in products:\n", + " print(f\"{product.capitalize()}: {inventory[product]}\")\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +141,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4, From 623ab7280afb4e4abe1a55614e88402bfda73728 Mon Sep 17 00:00:00 2001 From: davherdel Date: Thu, 11 Sep 2025 00:53:58 +0100 Subject: [PATCH 2/2] Submitting lab --- lab-python-data-structures.ipynb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 4c5eb0dd..ea9346f6 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -44,32 +44,38 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Enter available quantity for each product:\n", + "Enter available quantity for each product:\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ "\n", "Enter the name of 3 products to order:\n", "That product is not in the list. Please choose from: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", "\n", "Customer ordered the following products:\n", - "- book\n", "- mug\n", + "- hat\n", "\n", "Order Statistics:\n", "Total Products Ordered: 2\n", "Percentage of Products Ordered: 40.00%\n", "\n", "Updated Inventory:\n", - "T-shirt: 1111\n", - "Mug: 2221\n", - "Hat: 3333\n", - "Book: 4443\n", - "Keychain: 5555\n" + "T-shirt: 3\n", + "Mug: 1\n", + "Hat: 3\n", + "Book: 1\n", + "Keychain: 3\n" ] } ],