diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..dd0c171 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,6 +37,88 @@ "\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": 13, + "id": "acb16745-5e98-4e68-8b58-937cf28ef361", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "how many t-shirts? 23\n", + "how many mugs? 54\n", + "how many hats? 34\n", + "how many books? 23\n", + "how many keychains? 54\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 23, 'mug': 54, 'hat': 34, 'book': 23, 'keychain': 54}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Choose a product from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] keychain\n", + "Would you like to add another product? (yes/no) yes\n", + "Choose a product from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] book\n", + "Would you like to add another product? (yes/no) no\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'book', 'keychain'}\n", + "Order Statistics\n", + "Total Products Ordered: 2\n", + "Percentage of Products Ordered: 1.1%\n", + "There are 23 t-shirts\n", + "There are 54 mugs\n", + "There are 34 hats\n", + "There are 22 books\n", + "There are 53 keychains\n" + ] + } + ], + "source": [ + "products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory={}\n", + "for i in range(len(products)):\n", + " inventory[products[i]]=int(input('how many ' + products[i] + 's?'))\n", + "print(inventory)\n", + "customer_orders=[]\n", + "options=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "customer_orders=set()\n", + "addmore=True\n", + "while addmore==True:\n", + " choice= input('Choose a product from ' + str(options))\n", + " if choice in options:\n", + " customer_orders.add(choice)\n", + " yesno=input('Would you like to add another product? (yes/no)')\n", + " if yesno.lower()=='no':\n", + " addmore=False\n", + "print(customer_orders)\n", + "total_number_products=len(customer_orders)\n", + "total=sum(inventory.values())\n", + "percentage_ordered=round(len(customer_orders)/total*100,1)\n", + "order_status=('Total Products Ordered:',total_number_products,'Percentage of Products Ordered:',percentage_ordered)\n", + "print('Order Statistics')\n", + "print(f\"Total Products Ordered: {total_number_products}\")\n", + "print(f\"Percentage of Products Ordered: {percentage_ordered}%\" )\n", + "for i in customer_orders:\n", + " if inventory[i]!=0:\n", + " inventory[i]-=1\n", + "for key,value in inventory.items():\n", + " print(f\"There are {value} {key}s\")" + ] } ], "metadata": { @@ -55,7 +137,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,