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
191 changes: 189 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,198 @@
"\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": 87,
"metadata": {},
"outputs": [],
"source": [
"#1\n",
"\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 88,
"metadata": {},
"outputs": [],
"source": [
"#2\n",
"\n",
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 89,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 4, 'mug': 3, 'hat': 2}"
]
},
"execution_count": 89,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#3\n",
"\n",
"input1 = int(input(f\"Enter a quantity of t-shirt: {products} \"))\n",
"input2 = int(input(f\"Enter a quantity of mug: {products}\"))\n",
"input3 = int(input(f\"Enter a quantity of hats: {products}\"))\n",
"\n",
"inventory[\"t-shirt\"] = input1\n",
"inventory[\"mug\"] = input2\n",
"inventory[\"hat\"] = input3\n",
"\n",
"\n",
"inventory\n"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [],
"source": [
"#4\n",
"\n",
"customer_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 79,
"metadata": {},
"outputs": [],
"source": [
"#5\n",
"\n",
"input4 = input(f\"Dime que producto quieres: {products}\")\n",
"input5 = input(f\"Dime que producto quieres: {products}\")\n",
"input6 = input(f\"Dime que producto quieres: {products}\")\n",
"\n",
"customer_orders.add(input4)\n",
"customer_orders.add(input5)\n",
"customer_orders.add(input6)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'mug', 'hat', 't-shirt', 'book'}\n"
]
}
],
"source": [
"#6\n",
"\n",
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"60.0"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#7\n",
"\n",
"total_products_ordered= len(customer_orders)\n",
"total_products_ordered\n",
"\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"percentage_ordered\n"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics:\n",
"Total Products Ordered: 3 \n",
"Percentage of Products Ordered: 60.0 %\n"
]
}
],
"source": [
"#8 \n",
"\n",
"print(\"Order Statistics:\" \\\n",
"\"\\nTotal Products Ordered:\", total_products_ordered, \\\n",
"\"\\nPercentage of Products Ordered:\", percentage_ordered, \"%\")\n"
]
},
{
"cell_type": "code",
"execution_count": 92,
"metadata": {},
"outputs": [],
"source": [
"#9\n",
"inventory\n",
"\n",
"inventory[products[0]] = inventory[products[0]] - 1\n",
"inventory[products[1]] = inventory[products[1]] - 1\n",
"inventory[products[2]] = inventory[products[2]] - 1\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 95,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 2, 'mug': 1, 'hat': 0}"
]
},
"execution_count": 95,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#10\n",
"\n",
"inventory"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +255,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down