Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Up2date #291

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
307 changes: 306 additions & 1 deletion lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,311 @@
"\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": [],
"source": [
"#1\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#2\n",
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Ingresa la cantidad de t-shirt: 4\n",
"Ingresa la cantidad de mug: 5\n",
"Ingresa la cantidad de hat: 2\n",
"Ingresa la cantidad de book: 3\n",
"Ingresa la cantidad de keychain: 5\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Inventario actual:\n",
"{'t-shirt': 4, 'mug': 5, 'hat': 2, 'book': 3, 'keychain': 5}\n"
]
}
],
"source": [
"#3\n",
"# Recorrer la lista de productos y solicitar la cantidad para cada uno\n",
"\n",
"for product in products:\n",
" # Pedir al usuario ingresar la cantidad para cada producto\n",
" quantity = int(input(f\"Ingresa la cantidad de {product}: \"))\n",
" # Asignar la cantidad en el diccionario \"inventory\"\n",
" inventory[product] = quantity\n",
"\n",
"# Mostrar el inventario resultante\n",
"print(\"Inventario actual:\")\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"#4\n",
"customer_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Ingresa nombre de product1: mug\n",
"Ingresa nombre de product2: book\n",
"Ingresa nombre de product3: hat\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Nombre de productos que contiene la órden:\n",
"{'book', 'mug', 'hat'}\n"
]
}
],
"source": [
"#5\n",
"# Pedir al usuario ingresar los 3 tipos de producto que quiere en su orden\n",
"product1_name = input(f\"Ingresa nombre de product1: \")\n",
"product2_name = input(f\"Ingresa nombre de product2: \")\n",
"product3_name = input(f\"Ingresa nombre de product3: \")\n",
"# Asignar el nombre de producto en el set \"customer_orders\"\n",
"customer_orders.add (product1_name)\n",
"customer_orders.add (product2_name)\n",
"customer_orders.add (product3_name)\n",
"\n",
"print(\"Nombre de productos que contiene la órden:\")\n",
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Órden de cliente:\n",
"{'book', 'mug', 'hat'}\n"
]
}
],
"source": [
"#6\n",
"# Mostrar la customer order resultante\n",
"print(\"Órden de cliente:\")\n",
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"#7\n",
"#Total Products Number\n",
"total_products_number = len(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"total_products_number"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"#Percentage of Products Ordered\n",
"percentage_products_ordered = int((total_products_number / len(products))*100)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"60"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"percentage_products_ordered"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"#Guardar las estadísticas en una tupla\n",
"statistics = (total_products_number,percentage_products_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3, 60)"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"statistics"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60\n"
]
}
],
"source": [
"#8\n",
"#Mostrar las estadísticas\n",
"print(\"Order Statistics:\")\n",
"print(\"Total Products Ordered:\", total_products_number)\n",
"print(\"Percentage of Products Ordered:\", percentage_products_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"#9\n",
"for i in inventory:\n",
" inventory[i]-=1"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 3, 'mug': 4, 'hat': 1, 'book': 2, 'keychain': 4}"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inventory"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t-shirt 3\n",
"mug 4\n",
"hat 1\n",
"book 2\n",
"keychain 4\n"
]
}
],
"source": [
"#10\n",
"#Mostrar el inventario actualizado\n",
"for x,i in inventory.items():\n",
" print (x,i)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -68,7 +373,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down