diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..4a7314c 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,92 @@ "\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": "885278bf", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory: {}\n", + "{'t-shirt': 10}\n", + "{'t-shirt': 10, 'mug': 10}\n", + "{'t-shirt': 10, 'mug': 10, 'hat': 10}\n", + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10}\n", + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n", + "Inventory: {'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n", + "50\n", + "Invalid product. Please choose from the available products.\n", + "Invalid product. Please choose from the available products.\n", + "Invalid product. Please choose from the available products.\n", + "Customer orders: {'keychain', 'mug'}\n", + "Order statistics:\n", + "Total products ordered: 2\n", + "Percentage of products ordered: 4.17%\n", + "t-shirt: 10 remaining\n", + "mug: 9 remaining\n", + "hat: 10 remaining\n", + "book: 10 remaining\n", + "keychain: 9 remaining\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "\n", + "print(\"Inventory:\", inventory)\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}:\"))\n", + " inventory[product] = quantity \n", + " inventory_total = sum(inventory.values()) \n", + " print(inventory) \n", + "print(\"Inventory:\", inventory)\n", + "\n", + "\n", + "print(inventory_total)\n", + "\n", + "#2 Prompt the user to enter the name of a product\n", + "\n", + "customer_orders = set()\n", + "another_product = True \n", + "\n", + "while another_product != False:\n", + " order = input(\"Enter a product to order:\") #a prompt the user to enter the name of a product\n", + " if order in products:\n", + " customer_orders.add(order) #b add the product name to the customer_orders set\n", + " inventory_total -= 1\n", + " inventory[order] -= 1 #3 substract only products that are ordered from the inventory\n", + " another_product_input = input(\"Do you want to order another product? (Yes/No):\") #c ask the user if they want to order another product\n", + " if another_product_input.lower() == \"no\": #d continue to prompt the user until they indicate that they do not want to order another product\n", + " another_product = False\n", + " else:\n", + " print(\"Invalid product. Please choose from the available products.\")\n", + "print(\"Customer orders:\", customer_orders)\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "\n", + "\n", + "\n", + "\n", + "print(\"Order statistics:\")\n", + "print(\"Total products ordered:\", total_products_ordered)\n", + "percentage_ordered = (total_products_ordered / inventory_total) * 100\n", + "print(\"Percentage of products ordered:\", f\"{percentage_ordered:.2f}%\")\n", + "\n", + "for item, qty in inventory.items():\n", + " print(f\"{item}: {qty} remaining\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +136,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.3" } }, "nbformat": 4,