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
103 changes: 101 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,110 @@
"\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": 6,
"id": "7cdddcab",
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "70bd53b3",
"metadata": {},
"outputs": [],
"source": [
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "ac47ae96",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 5, 'mug': 6, 'hat': 7, 'book': 5, 'keychain': 4}"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"for product in products:\n",
" quantity = int(input(\"how many \" + product + \" are there?\"))\n",
" inventory[product] = quantity\n",
"inventory "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5c3d3d0b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt'}"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"customer_orders= set ()\n",
"question = input(\"Would you like to purchase an item (Y/N)?\")\n",
"while question.upper() == 'Y':\n",
" item = input(\"Which item would you like to order? (t-shirt, mug, hat, book, keychain) \")\n",
" if item.lower() in inventory:\n",
" customer_orders.add(item.lower())\n",
" else:\n",
" print(\"We don't sell that item\")\n",
" question.upper() = input(\"Would you like to purchase another item? \")\n",
"customer_orders\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "467be70e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 4, 'mug': 5, 'hat': 7, 'book': 5, 'keychain': 4}"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"for item in customer_orders:\n",
" inventory[item] = inventory[item] -1\n",
"inventory"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +154,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.7"
}
},
"nbformat": 4,
Expand Down