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
123 changes: 122 additions & 1 deletion lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,127 @@
"\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": 27,
"id": "2411affc-d8c5-4233-9ce9-e2d1dd08e2a3",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter name of product: mug\n",
"Enter yes or no to add another product: yes\n",
"Enter name of product: book\n",
"Enter yes or no to add another product: no\n"
]
},
{
"data": {
"text/plain": [
"{'book', 'mug'}"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"x=len(products)\n",
"customer_order=set()\n",
"count=0\n",
"\n",
"for count in range(x):\n",
" name=input(\"Enter name of product: \")\n",
" if name in products:\n",
" customer_order.add(name)\n",
" ask=input(\"Enter yes or no to add another product: \")\n",
" if ask==\"yes\":\n",
" count+=1\n",
" elif ask==\"no\":\n",
" break\n",
" else:\n",
" print(\"please add available\")\n",
" \n",
"customer_order\n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "d3e3747f-cde3-457f-bdce-5cc67df1ccf2",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter quantity: 2\n",
"Enter quantity: 3\n",
"Enter quantity: 4\n",
"Enter quantity: 5\n",
"Enter quantity: 6\n"
]
},
{
"data": {
"text/plain": [
"{'t-shirt': 2, 'mug': 3, 'hat': 4, 'book': 5, 'keychain': 6}"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory=dict()\n",
"for i in products:\n",
" quantity=int(input(\"Enter quantity: \"))\n",
" inventory[i]=quantity\n",
" \n",
"inventory \n"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "942af08b-0509-4542-bb91-f1fca1712d06",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 2, 'mug': 2, 'hat': 4, 'book': 4, 'keychain': 6}"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"for i in customer_order:\n",
" if i in inventory:\n",
" inventory[i]-=1\n",
"\n",
"inventory"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7d94412c-23c0-4bac-b222-c7f21408f294",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -55,7 +176,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down