Skip to content

Master #455

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
Empty file added .gitignore
Empty file.
164 changes: 164 additions & 0 deletions .ipynb_checkpoints/lab-python-flow-control-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "d3bfc191-8885-42ee-b0a0-bbab867c6f9f",
"metadata": {
"tags": []
},
"source": [
"# Lab | Flow Control"
]
},
{
"cell_type": "markdown",
"id": "3851fcd1-cf98-4653-9c89-e003b7ec9400",
"metadata": {},
"source": [
"## Exercise: Managing Customer Orders Optimized\n",
"\n",
"In the last lab, you were starting an online store that sells various products. To ensure smooth operations, you developed a program that manages customer orders and inventory.\n",
"\n",
"You did so without using flow control. Let's go a step further and improve this code.\n",
"\n",
"Follow the steps below to complete the exercise:\n",
"\n",
"1. Look at your code from the lab data structures, and improve repeated code with loops.\n",
"\n",
"2. Instead of asking the user to input the name of three products that a customer wants to order, do the following:\n",
" \n",
" a. Prompt the user to enter the name of a product that a customer wants to order.\n",
" \n",
" b. Add the product name to the \"customer_orders\" set.\n",
" \n",
" c. Ask the user if they want to add another product (yes/no).\n",
" \n",
" d. Continue the loop until the user does not want to add another product.\n",
"\n",
"3. Instead of updating the inventory by subtracting 1 from the quantity of each product, only do it for the products that were ordered (those in \"customer_orders\")."
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "c987c94a-72b3-4c0a-8091-6bd18e8a4411",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter the quantity available of each product: \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"t-shirt: 5\n",
"mug: 3\n",
"hat: 4\n",
"book: 2\n",
"keychain: 1\n",
"introduce the product that you want to order yes\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Product not available\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"¿Quieres añadir otro producto? (yes/no): yes\n",
"introduce the product that you want to order mug\n",
"¿Quieres añadir otro producto? (yes/no): yes\n",
"introduce the product that you want to order book\n",
"¿Quieres añadir otro producto? (yes/no): no\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Customer Orders:\n",
"- book\n",
"- mug\n"
]
}
],
"source": [
"# Paso 1: Lista de productos\n",
"\n",
"products= [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"# Paso 2: Diccionario vacío para el inventario\n",
"\n",
"inventory= {}\n",
"\n",
"# Paso 3: Pedir al usuario que inserte la cantidad de producto\n",
"\n",
"print(\"Enter the quantity available of each product: \")\n",
"for product in products:\n",
" quantity = int(input(f\"{product}: \"))\n",
" inventory[product]= quantity\n",
"\n",
"# Paso 4: Crear un conjunto vacío para los pedidos del cliente\n",
" \n",
"customer_orders= set()\n",
"while True:\n",
" product = input(\"introduce the product that you want to order \").strip().lower()\n",
"\n",
" if product in products:\n",
" customer_orders.add(product)\n",
" else:\n",
" print(\"Product not available\")\n",
"\n",
"# Paso 5: Pedir productos del cliente\n",
"\n",
" go_on = input(\"¿Do you want to add another product? (yes/no): \").strip().lower()\n",
" if go_on != \"yes\":\n",
" break\n",
" \n",
"# Paso 6: Mostrar pedidos\n",
"print(\"\\nCustomer Orders:\")\n",
"for item in customer_orders:\n",
" print(f\"- {item}\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7f41bc84-7304-476e-8c4b-762ac65cc864",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
103 changes: 102 additions & 1 deletion lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,107 @@
"\n",
"3. Instead of updating the inventory by subtracting 1 from the quantity of each product, only do it for the products that were ordered (those in \"customer_orders\")."
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "c987c94a-72b3-4c0a-8091-6bd18e8a4411",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter the quantity available of each product: \n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"t-shirt: 5\n",
"mug: 3\n",
"hat: 4\n",
"book: 2\n",
"keychain: 1\n",
"introduce the product that you want to order yes\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Product not available\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"¿Quieres añadir otro producto? (yes/no): yes\n",
"introduce the product that you want to order mug\n",
"¿Quieres añadir otro producto? (yes/no): yes\n",
"introduce the product that you want to order book\n",
"¿Quieres añadir otro producto? (yes/no): no\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Customer Orders:\n",
"- book\n",
"- mug\n"
]
}
],
"source": [
"# Paso 1: Lista de productos\n",
"\n",
"products= [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"# Paso 2: Diccionario vacío para el inventario\n",
"\n",
"inventory= {}\n",
"\n",
"# Paso 3: Pedir al usuario que inserte la cantidad de producto\n",
"\n",
"print(\"Enter the quantity available of each product: \")\n",
"for product in products:\n",
" quantity = int(input(f\"{product}: \"))\n",
" inventory[product]= quantity\n",
"\n",
"# Paso 4: Crear un conjunto vacío para los pedidos del cliente\n",
" \n",
"customer_orders= set()\n",
"while True:\n",
" product = input(\"introduce the product that you want to order \").strip().lower()\n",
"\n",
" if product in products:\n",
" customer_orders.add(product)\n",
" else:\n",
" print(\"Product not available\")\n",
"\n",
"# Paso 5: Pedir productos del cliente\n",
"\n",
" go_on = input(\"¿Do you want to add another product? (yes/no): \").strip().lower()\n",
" if go_on != \"yes\":\n",
" break\n",
" \n",
"# Paso 6: Mostrar pedidos\n",
"print(\"\\nCustomer Orders:\")\n",
"for item in customer_orders:\n",
" print(f\"- {item}\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7f41bc84-7304-476e-8c4b-762ac65cc864",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -55,7 +156,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.1"
}
},
"nbformat": 4,
Expand Down