From f5fbb2607159e11c1ca91a6e9371d1be199ddb6b Mon Sep 17 00:00:00 2001 From: Ricardo Santos Date: Thu, 15 Jan 2026 18:09:51 +0000 Subject: [PATCH] lab done: data structures --- lab-python-data-structures.ipynb | 82 +++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..4a684f59 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,89 @@ "\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": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'mug', 'book'}\n", + "{'t-shirt': 10, 'mug': 19, 'hat': 29, 'book': 39, 'keychain': 50}\n", + "Order Statistics:\n", + "Total Products Ordered:3\n", + "Percentage of Products Ordered:60.00%\n", + "Quantity of t-shirt is 10\n", + "Quantity of mug is 19\n", + "Quantity of hat is 29\n", + "Quantity of book is 39\n", + "Quantity of keychain is 50\n" + ] + } + ], + "source": [ + "#step 1\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "#step 2\n", + "inventory = {}\n", + "#step 3\n", + "for product in products:\n", + " while True:\n", + " n = input(f\"Please provide the amount of {product}\")\n", + " if n.isdigit() == True:\n", + " inventory[product]= int(n)\n", + " break\n", + " else:\n", + " print(\"Please provide an acceptable number of pieces\")\n", + "\n", + "#step 4\n", + "customer_orders = set()\n", + "#print(customer_orders)\n", + "\n", + "#step 5\n", + "i = 0\n", + "while i < 3:\n", + " prod = input(\"Please provide a product to order:\")\n", + " if prod not in products:\n", + " prod = input(\"That product is not available!\")\n", + " elif prod in customer_orders:\n", + " print(\"Warning: This product is already in your order!Please repeat your order.\")\n", + " else:\n", + " customer_orders.add(prod)\n", + " i += 1\n", + "#step 9\n", + " inventory[prod] -= 1\n", + "\n", + "#step 6\n", + "print(customer_orders)\n", + "#print(inventory)\n", + "\n", + "#step 7\n", + "total_prod = len(customer_orders)\n", + "perc_prod = (len(customer_orders) / len(products)) * 100\n", + "\n", + "#print(total_prod)\n", + "#print(perc_prod)\n", + "\n", + "order_status = (total_prod, perc_prod)\n", + "#type(order_status)\n", + "\n", + "#step 8\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered:{total_prod}\")\n", + "print(f\"Percentage of Products Ordered:{perc_prod:.2f}%\")\n", + "#step 10\n", + "for product in inventory:\n", + " print(f\"Quantity of {product} is {inventory[product]}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +146,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,