diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..6cc68db 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,89 @@ "\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": "5265a9d0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 20, 'mug': 20, 'hat': 20, 'book': 20, 'keychain': 20}\n", + "{'t-shirt'}\n", + "Order Statistics:\n", + "Total Products Ordered: <1>.\n", + "Percentage of Products Ordered: <20.0>%\n", + "This is the upadted inventory: \n", + "T-shirt: 19\n", + "Mug: 20\n", + "Hat: 20\n", + "Book: 20\n", + "Keychain: 20\n", + "\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {}\n", + "\n", + "for item in products:\n", + " quantity_of_item = int(input(f'Enter the quantity of {item}: '))\n", + " inventory[item] = quantity_of_item\n", + "\n", + "print(inventory)\n", + "\n", + "customer_orders = set()\n", + "\n", + "# Ask the user if they want to add another product (yes/no).\n", + "# Continue the loop until the user does not want to add another product.\n", + "\n", + "while True:\n", + " user_input = input(f'Enter the name of a product from {products}')\n", + " customer_orders.add(user_input)\n", + " question = input(f'Do you want to add another product (yes/no): ').lower()\n", + " if question == 'no':\n", + " break\n", + "\n", + "print(customer_orders)\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_of_prodcuts_ordered = total_products_ordered/len(products)*100\n", + "order_status = (total_products_ordered, percentage_of_prodcuts_ordered)\n", + "\n", + "print(\n", + " f'Order Statistics:\\n'\n", + " f'Total Products Ordered: <{total_products_ordered}>.\\n'\n", + " f'Percentage of Products Ordered: <{percentage_of_prodcuts_ordered}>%'\n", + ")\n", + "\n", + "# Instead of updating the inventory by subtracting 1 from the quantity of each product, \n", + "# only do it for the products that were ordered (those in \"customer_orders\").\n", + "\n", + "for item in customer_orders:\n", + " for product in products:\n", + " if item == product:\n", + " inventory[item] -= 1\n", + "\n", + "print(\n", + " f'This is the upadted inventory: \\n'\n", + " f'T-shirt: {inventory[\"t-shirt\"]}\\n'\n", + " f'Mug: {inventory[\"mug\"]}\\n'\n", + " f'Hat: {inventory[\"hat\"]}\\n'\n", + " f'Book: {inventory[\"book\"]}\\n'\n", + " f'Keychain: {inventory[\"keychain\"]}\\n'\n", + ")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +133,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,