From 1a95d5d1d9f37fa18a5308090b7de9b79da14fc3 Mon Sep 17 00:00:00 2001 From: Santiago Larrea Date: Mon, 28 Jul 2025 12:27:59 +0200 Subject: [PATCH] Lab flow controls --- README.md | 115 ------------------ lab-python-flow-control.ipynb | 63 ---------- lab-python-flow_controls (day 2).ipynb | 161 +++++++++++++++++++++++++ 3 files changed, 161 insertions(+), 178 deletions(-) delete mode 100644 README.md delete mode 100644 lab-python-flow-control.ipynb create mode 100644 lab-python-flow_controls (day 2).ipynb diff --git a/README.md b/README.md deleted file mode 100644 index 5eadc36..0000000 --- a/README.md +++ /dev/null @@ -1,115 +0,0 @@ -![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png) - -# LAB | Flow control - -
- - Learning Goals - - -
- - This exercise allows you to practice and apply the concepts and techniques taught in class. - - Upon completion of this exercise, you will be able to: - - - Use if-else statements to control the flow of execution in a program based on conditions. - - Use loops to repeat actions in a program. - - Combine if-else statements and loops to create more complex programs. - - Apply flow control statements to solve real-world programming problems. - -
-
- -
- - -
- - Prerequisites - - Before starting this lab, you should have learnt about: - -- Data types, operators and structures -- Flow control (if-else statements and loops) -
-
- -
- -## Introduction - -In this lab, you will practice how to use control structures to control the flow of a program's execution. Control structures are essential to programming as they enable the execution of a program to follow specific paths based on certain conditions. In this lab, you will practice writing code with various control structures, including if-else statements and loops. - -By the end of the lab, you should be able to identify situations that require the use of flow control, select the appropriate construct(s) to use, and write code that executes correctly and efficiently. You will also gain practical experience in coding, debugging, and testing programs that use flow control statements. This lab is designed for learners who are familiar with basic Python syntax and data types and are ready to expand their programming skills by learning how to control the flow of their programs. - -**This lab builds upon the solution from the previous exercise and enhances it by incorporating flow control mechanisms to create more robust and improved code.** - -
- -**Happy coding!** :heart: - -## Requirements - -- Fork this repo -- Clone it to your machine - - -## Getting Started - -Complete the challenges in the notebook. Follow the instructions and add your code and explanations as necessary. - -## Submission - -- Upon completion, run the following commands: - -```bash -git add . -git commit -m "Solved lab" -git push origin master -``` - -- Paste the link of your lab in Student Portal. - -## FAQs -
- I am stuck in the exercise and don't know how to solve the problem or where to start. -
- - If you are stuck in your code and don't know how to solve the problem or where to start, you should take a step back and try to form a clear question about the specific issue you are facing. This will help you narrow down the problem and come up with potential solutions. - - - For example, is it a concept that you don't understand, or are you receiving an error message that you don't know how to fix? It is usually helpful to try to state the problem as clearly as possible, including any error messages you are receiving. This can help you communicate the issue to others and potentially get help from classmates or online resources. - - - Once you have a clear understanding of the problem, you will be able to start working toward the solution. - - [Back to top](#faqs) - -
- - -
- I am unable to push changes to the repository. What should I do? -
- -There are a couple of possible reasons why you may be unable to *push* changes to a Git repository: - -1. **You have not committed your changes:** Before you can push your changes to the repository, you need to commit them using the `git commit` command. Make sure you have committed your changes and try pushing again. To do this, run the following terminal commands from the project folder: - ```bash - git add . - git commit -m "Your commit message" - git push - ``` -2. **You do not have permission to push to the repository:** If you have cloned the repository directly from the main Ironhack repository without making a *Fork* first, you do not have write access to the repository. -To check which remote repository you have cloned, run the following terminal command from the project folder: - ```bash - git remote -v - ``` -If the link shown is the same as the main Ironhack repository, you will need to fork the repository to your GitHub account first and then clone your fork to your local machine to be able to push the changes. - -**Note**: You should make a copy of your local code to avoid losing it in the process. - - [Back to top](#faqs) - -
diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb deleted file mode 100644 index f4c7391..0000000 --- a/lab-python-flow-control.ipynb +++ /dev/null @@ -1,63 +0,0 @@ -{ - "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\")." - ] - } - ], - "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.9.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/lab-python-flow_controls (day 2).ipynb b/lab-python-flow_controls (day 2).ipynb new file mode 100644 index 0000000..ae4b66e --- /dev/null +++ b/lab-python-flow_controls (day 2).ipynb @@ -0,0 +1,161 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "# Lab | Flow Controls\n", + "\n", + "Exercise: Managing Customer Orders Optimized\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", + "Look at your code from the lab data structures, and improve repeated code with loops.\n", + "\n", + "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", + "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": 13, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 5, 'mug': 5, 'hat': 5, 'book': 5, 'keychain': 5}\n" + ] + } + ], + "source": [ + "\n", + "for product in products:\n", + " quantity = int(input(f\"Quantity of product {product}: \"))\n", + " inventory[product] = quantity\n", + " \n", + "\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The product hat is not in the lis of ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "Your porducts are {'mug', 'hat', 'book'}\n" + ] + } + ], + "source": [ + "\n", + "customer_orders = set()\n", + "\n", + "for product in products:\n", + " chosen_product = input(f\"What porduct do you want to choose?{products}\")\n", + " if chosen_product in products:\n", + " customer_orders.add(chosen_product)\n", + " question = input(\"Do you want another product? yes/no\")\n", + " if question == \"yes\":\n", + " continue\n", + " elif question == \"no\":\n", + " break\n", + " else:\n", + " print(f\"The product {question} is not in the lis of {products}\")\n", + " else:\n", + " print(f\"Your {chosen_product} porduct is no in the list of porducts. {products}\")\n", + " \n", + " \n", + " \n", + "print(f\"Your porducts are {customer_orders}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 5, 'mug': 4, 'hat': 4, 'book': 4, 'keychain': 5}\n", + "t-shirt:5\n", + "mug:4\n", + "hat:4\n", + "book:4\n", + "keychain:5\n" + ] + } + ], + "source": [ + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + "\n", + "print(inventory)\n", + "\n", + "for key, values in inventory.items():\n", + " print(f\"{key}:{values}\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}