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
132 changes: 130 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,139 @@
"\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": 3,
"id": "d5793cc7",
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] #using this???\n",
"inventory = {}\n",
"\n",
"for product in products:\n",
" \"\"\" Prompt the user to enter the inventory count for each product and store it in the inventory dictionary.\"\"\"\n",
" inventory[product] = int(input(f\"Enter the inventory count for {product}: \"))\n",
"\n",
"# inv_shirt = int(input(\"Enter the inventory count for t-shirts: \"))\n",
"# inv_mug = int(input(\"Enter the inventory count for mugs: \"))\n",
"# inv_hat = int(input(\"Enter the inventory count for hats: \"))\n",
"# inv_book = int(input(\"Enter the inventory count for books: \"))\n",
"# inv_keychain = int(input(\"Enter the inventory count for keychains: \"))\n",
"\n",
"# inventory[\"t-shirt\"] = inv_shirt\n",
"# inventory[\"mug\"] = inv_mug\n",
"# inventory[\"hat\"] = inv_hat\n",
"# inventory[\"book\"] = inv_book\n",
"# inventory[\"keychain\"] = inv_keychain\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "eaddbdfe",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'hat'}\n"
]
}
],
"source": [
"customer_orders = set() #to set up an empty set, could also be {}, but it gave me an error\n",
"\n",
"while input(\"Do you want to place an order? (yes/no): \").lower() == \"yes\":\n",
" customer_orders.add(input(\"Enter one order (from `t-shirt`, `mug`, `hat`, `book`, `keychain`): \"))\n",
"\n",
"#attention with the double quotes inside the string\n",
"# customer_orders.add(input(\"Enter one order (from `t-shirt`, `mug`, `hat`, `book`, `keychain`): \"))\n",
"# customer_orders.add(input(\"Enter another order (from `t-shirt`, `mug`, `hat`, `book`, `keychain`): \"))\n",
"# customer_orders.add(input(\"Enter third order (from `t-shirt`, `mug`, `hat`, `book`, `keychain`): \"))\n",
"\n",
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "cccc9ba9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" Order Statistics:\n",
" Total Products Ordered: 1\n",
" Percentage of Products Ordered: 10.0% \n",
" \n"
]
}
],
"source": [
"total_products_ordered = len(customer_orders)\n",
"total_in_house = sum(inventory.values())\n",
"percentage_ordered = (total_products_ordered / total_in_house) * 100\n",
"order_status = (total_products_ordered, percentage_ordered)\n",
"\n",
"print(f\"\"\"\n",
" Order Statistics:\n",
" Total Products Ordered: {total_products_ordered}\n",
" Percentage of Products Ordered: {percentage_ordered}% \n",
" \"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "06bf22ed",
"metadata": {},
"outputs": [],
"source": [
"for product in customer_orders:\n",
" if product in inventory and inventory[product] > 0:\n",
" inventory[product] -= 1"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "0678d94a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Updated Inventory:\n",
" t-shirt: 0\n",
" mug: 1\n",
" hat: 1\n",
" book: 3\n",
" keychain: 4\n",
" \n"
]
}
],
"source": [
"print(f\"\"\"Updated Inventory:\n",
" t-shirt: {inventory['t-shirt']}\n",
" mug: {inventory['mug']}\n",
" hat: {inventory['hat']}\n",
" book: {inventory['book']}\n",
" keychain: {inventory['keychain']}\n",
" \"\"\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +183,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down