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
80 changes: 78 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,87 @@
"\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": 32,
"id": "4b0c822f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 47, 'mug': 384, 'hat': 38, 'book': 299, 'keychain': 29}\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"\n",
"for product in products: \n",
" amount = int(input(f\"How many products are of {product}?\"))\n",
" inventory[product] = amount\n",
" \n",
"print(inventory)\n"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "32638449",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Thank you for your order! :)\n",
"{'mug', 'book'}\n"
]
}
],
"source": [
"\n",
"costumer_orders = set()\n",
"petition = \"Yes\".lower()\n",
"\n",
"while petition == \"Yes\".lower():\n",
" order = input(\"Write a product to order\")\n",
" costumer_orders.add(order)\n",
" petition = input(\"Do you want to order another product? (Yes/No)\").lower()\n",
"\n",
" \n",
"print(\"Thank you for your order! :)\")\n",
"print(costumer_orders)\n"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "8c6abde8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 47, 'mug': 383, 'hat': 38, 'book': 298, 'keychain': 29}\n"
]
}
],
"source": [
"\n",
"for product in costumer_orders:\n",
" inventory[product] -= 1 \n",
"print(inventory)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "ds",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +131,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.12"
}
},
"nbformat": 4,
Expand Down