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
135 changes: 133 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,142 @@
"\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": 17,
"id": "6b2efcf0",
"metadata": {},
"outputs": [],
"source": [
"#This is Kyle Solving the Lab\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "0642ca8f",
"metadata": {},
"outputs": [],
"source": [
"products= [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "ceaf2fba",
"metadata": {},
"outputs": [],
"source": [
"inventory={}"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "ae3eaf53",
"metadata": {},
"outputs": [],
"source": [
"inventory = {}\n",
"\n",
"for product in products:\n",
" inventory[product] = int(input(f\"Input number of {product}: \"))"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "aef93432",
"metadata": {},
"outputs": [],
"source": [
"customer_orders= set()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "d97e7347",
"metadata": {},
"outputs": [],
"source": [
"order= input(\"select a product to order:\")\n",
"customer_orders.add(order)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "a1b11680",
"metadata": {},
"outputs": [],
"source": [
"continue_order= input(\"would you like to order another product?:\")"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "cd589653",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Thank you, your order(s) have been ordered.\n"
]
}
],
"source": [
"continue_order = \"yes\"\n",
"\n",
"while continue_order == \"yes\":\n",
" order = input(\"Select a product to order: \")\n",
" customer_orders.add(order)\n",
" continue_order = input(\"Would you like to order another product? yes/no: \").lower()\n",
"\n",
"print(\"Thank you, your order(s) have been ordered.\")\n"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "087e0960",
"metadata": {},
"outputs": [],
"source": [
"for product in customer_orders:\n",
" inventory[product] = inventory[product] - 1\n"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "44eb4829",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 5, 'mug': 4, 'hat': 5, 'book': 4, 'keychain': 5}"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inventory"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +186,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.9.10"
}
},
"nbformat": 4,
Expand Down