From c59a4d2609f414cdb8c87dc1e389398a211df429 Mon Sep 17 00:00:00 2001 From: Orgo4ever <163662002+Orgo4ever@users.noreply.github.com> Date: Tue, 16 Jun 2026 17:24:33 +0200 Subject: [PATCH] Solved lab 2 This is the adjustments to the first lab to complete the second one. --- lab-python-flow-control.ipynb | 176 ++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..12041b8 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,6 +37,182 @@ "\n", "3. Instead of updating the inventory by subtracting 1 from the quantity of each product, only do it for the products that were ordered (those in \"customer_orders\")." ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6b2efcf0", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "#This is Kyle Solving the Lab\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5b65ea77", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e94cae12", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "inventory={}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "594de533", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + "\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "69d10e9e", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "customer_orders=set()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5c8aee42", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "while True:\n", + " product_order = input(\"Enter the name of a product: \")\n", + "\n", + " if product_order in products:\n", + " customer_orders.add(product_order)\n", + " else:\n", + " print(\"That product is not available.\")\n", + "\n", + " add_another = input(\"Do you want to add another product? (yes/no): \")\n", + "\n", + " if add_another.lower() == \"no\":\n", + " break" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7bfed850", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "print(customer_orders)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f36032f3", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "total_products_ordered=len(customer_orders)\n", + "print(total_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b2b04ae9", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "percentage_ordered = (len(customer_orders) / len(products)) * 100\n", + "print(f\"percentage of products ordered: {percentage_ordered}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "99832692", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "order_status=(total_products_ordered, percentage_ordered)\n", + "print(order_status)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a2488feb", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "for product in customer_orders:\n", + " inventory[product] = inventory[product] - 1 \n", + "\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n" + ] } ], "metadata": {