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
64 changes: 62 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,71 @@
"\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": 1,
"id": "cae91431",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"inventory count are {'t-shirt': 5, 'mug': 4, 'hat': 5, 'book': 4, 'keychain': 5}\n",
"customer orders: {'book', 'mug'}\n"
]
}
],
"source": [
"#defining list\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"\n",
"#empty dictionary and input \n",
"inventory = {}\n",
"\n",
"for item in products:\n",
" quantity = int(input(f\"Please insert inventory count for {item} avalable\"))\n",
" inventory[item] = quantity\n",
"\n",
"#create an empty set\n",
"customer_orders = set()\n",
"\n",
"#setup a while statement to ask the order + if they want to continue ordering. \n",
"while True:\n",
" product_name = input(\"Name of porduct customer wants to order: \")\n",
" customer_orders.add(product_name)\n",
"\n",
" while True:\n",
" continue_choice = input(f\"do you want to add another porduct? yes/no\")\n",
" \n",
" if continue_choice == \"yes\": \n",
" break\n",
" elif continue_choice == \"no\":\n",
" break\n",
" else:\n",
" print(f\"invalid input, please enter yes or no\")\n",
"\n",
" if continue_choice == \"no\":\n",
" break\n",
"\n",
"\n",
"#subtract the quantity from the inventory\n",
"for product in customer_orders:\n",
" inventory[product] -= 1\n",
"\n",
"\n",
"\n",
"#Below is the check to see inputs made by the user\n",
"print(f\"inventory count are {inventory}\")\n",
"print(f\"customer orders: {customer_orders}\")\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "data-analytics",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +115,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.9.23"
}
},
"nbformat": 4,
Expand Down