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
181 changes: 179 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,188 @@
"\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": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 2, 'mug': 2, 'book': 2, 'hat': 2, 'keychain': 2}\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"book\", \"hat\", \"keychain\"]\n",
"inventory = {}\n",
"inv_t_shirt = int(input(\"Add quantity of T-shirts in inventory: \"))\n",
"inventory[\"t-shirt\"]=inv_t_shirt\n",
"inv_mug = int(input(\"Add quantity of mugs in inventory: \"))\n",
"inventory[\"mug\"]=inv_mug\n",
"inv_book = int(input(\"Add quantity of books in inventory: \"))\n",
"inventory[\"book\"]=inv_book\n",
"inv_hat = int(input(\"Add quantity of hats in inventory: \"))\n",
"inventory[\"hat\"]=inv_hat\n",
"inv_keychain = int(input(\"Add quantity of keychains in inventory: \"))\n",
"inventory[\"keychain\"]=inv_keychain\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt', 'book', 'mug'}\n"
]
}
],
"source": [
"customer_order = set()\n",
"first_order = input(\"Please, add the first order from inventory products: \")\n",
"customer_order.add(first_order)\n",
"second_order = input(\"Please, add the second order from inventory products: \")\n",
"customer_order.add(second_order)\n",
"third_order = input(\"Please, add the third order from inventory products: \")\n",
"customer_order.add(third_order)\n",
"print(customer_order)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Total_products_ord = len(customer_order)\n",
"\n",
"Total_products_ord"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"60.0\n"
]
}
],
"source": [
"Percentage = len(customer_order) / len(inventory) * 100\n",
"print(Percentage)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(3, 60.0)\n"
]
}
],
"source": [
"order_status = ()\n",
"order_status = order_status + (3, 60.0)\n",
"print(order_status)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0\n"
]
}
],
"source": [
"print(f\"Order statistics:\\nTotal Products Ordered: {Total_products_ord}\\nPercentage of Products Ordered: {Percentage}\")\n",
"#en un principio había hecho 3 líneas de print, pero me apetecía saber de que manera podía saltar de línea el texto escrito."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 1, 'mug': 1, 'book': 1, 'hat': 2, 'keychain': 2}\n"
]
}
],
"source": [
"inventory[\"book\"] -= 1\n",
"inventory[\"t-shirt\"]-= 1\n",
"inventory[\"mug\"]-= 1\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t-shirt: 1\n",
"mug: 1\n",
"book: 1\n",
"hat: 2\n",
"keychain: 2\n"
]
}
],
"source": [
"print(\"t-shirt: \", inventory[\"t-shirt\"])\n",
"print(\"mug: \", inventory[\"mug\"])\n",
"print(\"book: \", inventory[\"book\"])\n",
"print(\"hat: \", inventory[\"hat\"])\n",
"print(\"keychain: \", inventory[\"keychain\"])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +245,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down