From 31632887c500bc85447614fe1f05029af4591561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandra=20Isabel=20Correia=20Gon=C3=A7alves?= Date: Sat, 19 Sep 2026 11:51:53 +0100 Subject: [PATCH] Solved lab --- .vscode/launch.json | 18 ++++++++ lab-python-data-structures.ipynb | 74 +++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..61cb8aba --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,18 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + + + { + "name": "Python Debugger: Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..502160a2 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,81 @@ "\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": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] #1\n", + "inventory = dict.fromkeys(products) #2\n", + "print(inventory)\n", + "\n", + "for product in products:\n", + " inventory[product] = int(input(f\"Quantity of {product}:\")) #3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set() #4\n", + "type(customer_orders)\n", + "\n", + "while len(customer_orders) < 3: #5\n", + " product = input(f\"Choose an item from {customer_orders}:\")\n", + "\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"That item is not in the list.\")\n", + "\n", + "print(customer_orders) #6" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "total = len(customer_orders) #7\n", + "\n", + "print(total)\n", + "\n", + "percentage = len(customer_orders) / len(products) * 100\n", + "\n", + "print(f\"{percentage:.2f}%\")\n", + "\n", + "order_status = (\n", + " total, \n", + " f\"{percentage:.2f}%\"\n", + ")\n", + "print(order_status)\n", + "print(f\"Total of Products Ordered: {order_status[0]}\") #8\n", + "print(f\"Percentage of Products Ordered: {order_status[1]}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for product in inventory: #9\n", + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + "print(inventory) #10\n", + " " + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +138,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.9.6" } }, "nbformat": 4,