diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..ea9346f6 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,99 @@ "\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": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "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", + "- 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: 3\n", + "Mug: 1\n", + "Hat: 3\n", + "Book: 1\n", + "Keychain: 3\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 +147,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,