diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..e7f22443 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -1,62 +1,77 @@ { "cells": [ { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "# Lab | Data Structures " - ] - }, - { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, + "id": "initial_id", "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", + "for product in products:\n", + " quantity=int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product]=quantity\n", "\n", - "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", + "print(inventory)\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", + "#5\n", + "for i in range(3):\n", + " item = input(f\"Enter product {i+1} you want to order ['t-shirt', 'mug', 'hat', 'book', 'keychain']: \")\n", + " while item not in products:\n", + " item = input(\"Invalid product.Please choose from this list ['t-shirt', 'mug', 'hat', 'book', 'keychain']:\")\n", "\n", - "4. Create an empty set called `customer_orders`.\n", + " customer_orders.add(item)\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", + "#6\n", + "print(\"Products ordered by customer:\")\n", + "for item in customer_orders:\n", + " print(item)\n", + " \n", + "#7\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", - "6. Print the products in the `customer_orders` set.\n", + "#8\n", + "\"\"\"\n", + "Order Statistics:\n", + "Total Products Ordered: \n", + "Percentage of Products Ordered: %\n", + "\"\"\"\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", + "print(\"Order Statistics:\")\n", + "print(\"Total Products Ordered:\", total_products_ordered)\n", + "print(\"Percentage of Products Ordered:\", percentage_ordered, \"%\")\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", + "#9\n", + "for item in customer_orders:\n", + " inventory[item] -= 1\n", "\n", - "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", - "\n", - "10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", - "\n", - "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " + "#10\n", + "print(\"Inventory after order:\")\n", + "for item in inventory:\n", + " print(item, inventory[item])\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "345dd5b6-410a-4e62-9ff2-e834fa6e8df7", + "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 +83,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 }