diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..7fb5982 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,6 +37,63 @@ "\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": "2df46550", + "metadata": {}, + "outputs": [], + "source": [ + "products_list = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "inventory = { }\n", + "for product in products_list:\n", + " while True:\n", + " quantity_input = input(f\"Enter the quantity for {product}: \") or '0'\n", + " try:\n", + " quantity = int(quantity_input)\n", + " inventory[product] = quantity\n", + " break\n", + " except ValueError:\n", + " print(\"Please enter a valid integer.\")\n", + "\n", + "customer_orders = set()\n", + "\n", + "while True:\n", + " product = input(\"Enter a product (choose from 't-shirt', 'mug', 'hat', 'book', 'keychain'): \").strip().lower()\n", + " \n", + " if product in products_list:\n", + " customer_orders.add(product)\n", + " print(f\"{product} has been added to the order.\")\n", + " else:\n", + " print(f\"{product} is not a valid choice and will not be added.\")\n", + " add_more = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " \n", + " if add_more != 'yes':\n", + " break\n", + "\n", + "print(\"products in order:\", customer_orders)\n", + "\n", + "total_ordered = len(customer_orders)\n", + "total_available = len(products_list)\n", + "percentage = (total_ordered / total_available) * 100\n", + "\n", + "order_status = (total_ordered, percentage)\n", + "\n", + "print(\"\\norder statistics:\")\n", + "print(f\"total products ordered: {order_status[0]}\")\n", + "print(f\"percentage of products ordered: {order_status[1]:.2f}%\")\n", + "\n", + "for product in customer_orders:\n", + " if product in inventory and inventory[product] > 0:\n", + " inventory[product] -= 1\n", + " print(f\"Successfully ordered {product}. Remaining: {inventory[product]}\")\n", + " \n", + "\n", + "print(\"\\nupdated inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n" + ] } ], "metadata": {