Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [



{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
74 changes: 72 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,81 @@
"\n",
"Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] #1\n",
"inventory = dict.fromkeys(products) #2\n",
"print(inventory)\n",
"\n",
"for product in products:\n",
" inventory[product] = int(input(f\"Quantity of {product}:\")) #3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"customer_orders = set() #4\n",
"type(customer_orders)\n",
"\n",
"while len(customer_orders) < 3: #5\n",
" product = input(f\"Choose an item from {customer_orders}:\")\n",
"\n",
" if product in products:\n",
" customer_orders.add(product)\n",
" else:\n",
" print(\"That item is not in the list.\")\n",
"\n",
"print(customer_orders) #6"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"total = len(customer_orders) #7\n",
"\n",
"print(total)\n",
"\n",
"percentage = len(customer_orders) / len(products) * 100\n",
"\n",
"print(f\"{percentage:.2f}%\")\n",
"\n",
"order_status = (\n",
" total, \n",
" f\"{percentage:.2f}%\"\n",
")\n",
"print(order_status)\n",
"print(f\"Total of Products Ordered: {order_status[0]}\") #8\n",
"print(f\"Percentage of Products Ordered: {order_status[1]}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for product in inventory: #9\n",
" if inventory[product] > 0:\n",
" inventory[product] -= 1\n",
"print(inventory) #10\n",
" "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +138,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down