1212
Week 1 Lab Data Structures by LaloMontealvo · Pull Request #535 · data-bootcamp-v4/lab-python-data-structures · GitHub
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
72 changes: 61 additions & 11 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"# Lab | Data Structures "
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -50,11 +41,70 @@
"\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": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'hat'}\n",
"Order Statistics:\n",
"Total Products Ordered: 1\n",
"Percentage of Products Ordered: 20.0%\n",
"{'hat', 'mug'}\n",
"Order Statistics:\n",
"Total Products Ordered: 2\n",
"Percentage of Products Ordered: 40.0%\n",
"{'book', 'hat', 'mug'}\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0%\n",
"t-shirt: 38\n",
"mug: 59\n",
"hat: 24\n",
"book: 869\n",
"keychain: 20\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"for product in products:\n",
" quantity = int(input(f\"Enter the quantity of {product}: \"))\n",
" inventory[product] = quantity\n",
"\n",
"customer_orders = set()\n",
"for i in range(3):\n",
" order = input(f\"Enter the name of product {i+1} to order: \")\n",
" customer_orders.add(order)\n",
" print(customer_orders)\n",
"\n",
" total_products_ordered = len(customer_orders)\n",
" percentage_ordered = (total_products_ordered / len(products)) * 100\n",
" order_status = (total_products_ordered, percentage_ordered)\n",
" print(\"Order Statistics:\") \n",
" print(f\"Total Products Ordered: {order_status[0]}\")\n",
" print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n",
"\n",
"for product in customer_orders:\n",
" if product in inventory:\n",
" inventory[product] -= 1\n",
"\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\") \n",
" \n",
" "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "data-analyst",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +118,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down