Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 87 additions & 3 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,97 @@
"\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": 2,
"id": "88cd58a9-3672-4ca4-97e5-78e2a285e378",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Please enter stock for article t-shirt 1\n",
"Please enter stock for article mug 2\n",
"Please enter stock for article hat 3\n",
"Please enter stock for article book 4\n",
"Please enter stock for article keychain 5\n",
"Would you like to order? Please enter 1 for yes and 0 for no. 1\n",
"Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain 1\n",
"Would you like to order something else? Please enter 1 for yes and 0 for no. 1\n",
"Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain 2\n",
"Would you like to order something else? Please enter 1 for yes and 0 for no. 0\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Thank you for your order.\n",
"{'mug', 'hat'}\n",
"Order Statistics:\n",
"Total Products Ordered: 2\n",
"Percentage of Products Ordered: 40.0 %\n",
"The stock for t-shirt is 1\n",
"The stock for mug is 1\n",
"The stock for hat is 2\n",
"The stock for book is 4\n",
"The stock for keychain is 5\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"\n",
"for product in products:\n",
" stock = int(input(f\"Please enter stock for article {product}\"))\n",
" inventory[product] = stock\n",
"\n",
"customer_orders = set()\n",
"\n",
"question = int(input(\"Would you like to order? Please enter 1 for yes and 0 for no.\"))\n",
"\n",
"while question == 1:\n",
" customer_orders.add(products[int(input(\"Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain\"))])\n",
" question = int(input(\"Would you like to order something else? Please enter 1 for yes and 0 for no.\"))\n",
"\n",
"print(\"Thank you for your order.\")\n",
"\n",
"print(customer_orders)\n",
"\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (len(customer_orders)/len(inventory.values()))*100\n",
"\n",
"order_status = (total_products_ordered, percentage_ordered)\n",
"\n",
"print(f\"\"\"Order Statistics:\n",
"Total Products Ordered: {total_products_ordered}\n",
"Percentage of Products Ordered: {percentage_ordered} %\"\"\")\n",
"\n",
"for product in customer_orders:\n",
" inventory[product] -= 1\n",
"\n",
"for product in products:\n",
" print(\"The stock for\", product, \"is\", inventory[product])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a7166455-ca7c-4cba-a43a-a4b22ab6cc67",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "python3"
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -55,7 +139,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down