From d7ee276d858fd1f689d4006ba368150183c03602 Mon Sep 17 00:00:00 2001 From: NavHat74 Date: Sat, 17 Jan 2026 15:36:05 +0100 Subject: [PATCH 1/3] resolution --- lab-python-data-structures.ipynb | 117 ++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..1b537762 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -1,5 +1,118 @@ { "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{}\n" + ] + } + ], + "source": [ + "inventory = {}\n", + "print(inventory)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "print(products)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "print(products)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 5}\n", + "{'t-shirt': 5, 'mug': 3}\n", + "{'t-shirt': 5, 'mug': 3, 'hat': 4}\n", + "{'t-shirt': 5, 'mug': 3, 'hat': 4, 'book': 6}\n", + "{'t-shirt': 5, 'mug': 3, 'hat': 4, 'book': 6, 'keychain': 7}\n" + ] + } + ], + "source": [ + "for product in products:\n", + " quantity = int(input(f\"Enter quantity for (product): \"))\n", + " inventory[product] = quantity\n", + " \n", + " print(inventory)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set()\n" + ] + } + ], + "source": [ + "print(customer_orders)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": { @@ -54,7 +167,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +181,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4, From a15976149e5f846454e58c5dd44d4cace6b5f5f6 Mon Sep 17 00:00:00 2001 From: NavHat74 Date: Sat, 17 Jan 2026 16:51:23 +0100 Subject: [PATCH 2/3] Complete customer orders lab --- lab-python-data-structures.ipynb | 175 ++++++++++++++----------------- 1 file changed, 79 insertions(+), 96 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 1b537762..fbc9b8cb 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -2,117 +2,100 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{}\n" + "Customer orders: {'hat', 'mug', 'book'}\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0%\n", + "Updated Inventory:\n", + "t-shirt: 25\n", + "mug: 44\n", + "hat: 31\n", + "book: 66\n", + "keychain: 21\n" ] } ], "source": [ - "inventory = {}\n", - "print(inventory)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" - ] - } - ], - "source": [ - "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", - "print(products)\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ + "\n", + "# step 1: define product list\n", + "\n", "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", - "print(products)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'t-shirt': 5}\n", - "{'t-shirt': 5, 'mug': 3}\n", - "{'t-shirt': 5, 'mug': 3, 'hat': 4}\n", - "{'t-shirt': 5, 'mug': 3, 'hat': 4, 'book': 6}\n", - "{'t-shirt': 5, 'mug': 3, 'hat': 4, 'book': 6, 'keychain': 7}\n" - ] - } - ], - "source": [ + "\n", + "\n", + "\n", + "# step 2: create empty inventory dictionary\n", + "\n", + "inventory = {}\n", + "\n", + "\n", + "\n", + "# step 3: ask user for quantity of each product\n", + "\n", "for product in products:\n", - " quantity = int(input(f\"Enter quantity for (product): \"))\n", + " quantity = int(input(f\"Enter quantity for {product}: \"))\n", " inventory[product] = quantity\n", - " \n", - " print(inventory)\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "customer_orders = set()\n" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "set()\n" - ] - } - ], - "source": [ - "print(customer_orders)\n" + "\n", + "\n", + "\n", + "# step 4: create empty set for customer orders\n", + "\n", + "customer_orders = set()\n", + "\n", + "\n", + "\n", + "# step 5: ask user to input 3 products to order\n", + "\n", + "for i in range(3):\n", + " product = input(f\"Enter product {i + 1} to order: \")\n", + " customer_orders.add(product)\n", + "\n", + "\n", + "\n", + "# step 6: print customer orders\n", + "\n", + "print(\"Customer orders:\", customer_orders)\n", + "\n", + "\n", + "\n", + "# step 7: calculate statistics and store in tuple\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "#print(f\"Total products ordered: {total_products_ordered}\")\n", + "#print(f\"Percentage of products ordered: {percentage_ordered}%\")\n", + "#print(\"Order status tuple:\", order_status)\n", + "\n", + "\n", + "# step 8: print order statistics in required format\n", + "\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {total_products_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {percentage_ordered}%\")\n", + "\n", + "\n", + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + "\n", + "# step 10: print updated inventory\n", + "\n", + "print(\"Updated Inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n", + "\n", + "\n" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "metadata": { From b23d80ff87a428bdafb5afba6b3806d50aa20aed Mon Sep 17 00:00:00 2001 From: NavHat74 Date: Thu, 22 Jan 2026 18:59:34 +0100 Subject: [PATCH 3/3] Complete lap: Python data structures --- lab-python-data-structures.ipynb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index fbc9b8cb..56dee760 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -14,11 +14,11 @@ "Total Products Ordered: 3\n", "Percentage of Products Ordered: 60.0%\n", "Updated Inventory:\n", - "t-shirt: 25\n", - "mug: 44\n", - "hat: 31\n", - "book: 66\n", - "keychain: 21\n" + "t-shirt: 13\n", + "mug: 1\n", + "hat: 7\n", + "book: 89\n", + "keychain: 40\n" ] } ],