diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..2869d74b 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -1,62 +1,85 @@ { "cells": [ { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "# Lab | Data Structures " - ] - }, - { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, + "id": "eaf34e39-6584-4e7a-897e-5b0bf00bedb3", "metadata": {}, + "outputs": [], "source": [ - "## Exercise: Managing Customer Orders\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\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", + "inventory = {}\n", "\n", - "Follow the steps below to complete the exercise:\n", + "tshirt = int(input(\"Enter # of t-shirts: \"))\n", + "mug = int(input(\"Enter # of mugs: \"))\n", + "hat = int(input(\"Enter # of hats: \"))\n", + "book = int(input(\"Enter # of books: \"))\n", + "keychain = int(input(\"Enter # of keychains: \"))\n", "\n", - "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", + "inventory[\"t-shirt\"] = tshirt\n", + "inventory[\"mug\"] = mug\n", + "inventory[\"hat\"] = hat\n", + "inventory[\"book\"] = book\n", + "inventory[\"keychain\"] = keychain\n", "\n", - "2. Create an empty dictionary called `inventory`.\n", + "customer_orders = set()\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(\"Available products:\", products)\n", + "product1 = input(\"Name of the first product: \")\n", + "product2 = input(\"Name of the second product: \")\n", + "product3 = input(\"Name of the third product: \")\n", "\n", - "4. Create an empty set called `customer_orders`.\n", + "customer_orders = {product1, product2, product3}\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(\"Products in the customer_orders set:\")\n", + "print(customer_orders)\n", "\n", - "6. Print the products in the `customer_orders` set.\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", + "print()\n", + "print(\"Order Statistics:\")\n", + "print(\"Total Products Ordered:\", total_products_ordered)\n", + "print(\"Percentage of Products Ordered:\", percentage_ordered, \"%\")\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", + "if \"t-shirt\" in customer_orders:\n", + " inventory[\"t-shirt\"] -= 1\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", + "if \"mug\" in customer_orders:\n", + " inventory[\"mug\"] -= 1\n", "\n", - "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", + "if \"hat\" in customer_orders:\n", + " inventory[\"hat\"] -= 1\n", "\n", - "10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "if \"book\" in customer_orders:\n", + " inventory[\"book\"] -= 1\n", "\n", - "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " + "if \"keychain\" in customer_orders:\n", + " inventory[\"keychain\"] -= 1\n", + "\n", + "print(\"Updated inventory after the order:\")\n", + "print(\"t-shirt:\", inventory[\"t-shirt\"])\n", + "print(\"mug:\", inventory[\"mug\"])\n", + "print(\"hat:\", inventory[\"hat\"])\n", + "print(\"book:\", inventory[\"book\"])\n", + "print(\"keychain:\", inventory[\"keychain\"])" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b4364314-6c92-4855-9577-daedd8961d32", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -68,9 +91,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4, - "nbformat_minor": 4 + "nbformat_minor": 5 }