diff --git a/.ipynb_checkpoints/README-checkpoint.md b/.ipynb_checkpoints/README-checkpoint.md new file mode 100644 index 00000000..b66b7a56 --- /dev/null +++ b/.ipynb_checkpoints/README-checkpoint.md @@ -0,0 +1,117 @@ +![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png) + +# LAB | Python Data structures + +
+ +

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 different data structures such as lists, dictionaries, sets and tuples, to store and manipulate data. + - Access and modify data stored in data structures using indexing, slicing, or built-in methods. + +
+
+ +
+ +
+ +

Prerequisites

+
+Before this starting this lab, you should have learnt about: + +- Basic Python syntax +- Variables +- Data types, operators and structures + +
+
+ +
+ +## Introduction + +Welcome to your first data analytics bootcamp lab! In this lab, you will have the opportunity to dive into one of the fundamental building blocks of Python programming: data structures. + +As you may already know, data structures are collections of values that can be used to organize and manipulate data more efficiently, such as lists, dictionaries, sets, and tuples. + +Understanding data structures is essential to working with data in any programming language. It is a common practice to modify or manipulate data structures when performing various operations, such as filtering data, performing calculations, or extracting specific data elements. + +Through a series of lab exercises, you will have the opportunity to apply the concepts and techniques learned in class and gain a solid understanding of data structures. + +
+ +**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/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb new file mode 100644 index 00000000..bb67b88b --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,322 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "# Lab | Data Structures " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise: Managing Customer Orders\n", + "\n", + "As part of a business venture, you are starting an online store that sells various products. To ensure smooth operations, you need to develop a program that manages customer orders and inventory.\n", + "\n", + "Follow the steps below to complete the exercise:\n", + "\n", + "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", + "\n", + "2. Create an empty dictionary called `inventory`.\n", + "\n", + "3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n", + "\n", + "4. Create an empty set called `customer_orders`.\n", + "\n", + "5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set.\n", + "\n", + "6. Print the products in the `customer_orders` set.\n", + "\n", + "7. Calculate the following order statistics:\n", + " - Total Products Ordered: The total number of products in the `customer_orders` set.\n", + " - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", + " \n", + " Store these statistics in a tuple called `order_status`.\n", + "\n", + "8. Print the order statistics using the following format:\n", + " ```\n", + " Order Statistics:\n", + " Total Products Ordered: \n", + " Percentage of Products Ordered: % \n", + " ```\n", + "\n", + "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", + "\n", + "10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "\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": 103, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] #product list" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {} # empty inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "number of t-shirts: 5\n", + "number of mugs: 6\n", + "number of hats: 7\n", + "number of books: 8\n", + "number of keychains: 5\n" + ] + } + ], + "source": [ + "tvalue=int(input(\"number of t-shirts: \")) #int() makes the input a integer\n", + "mvalue=int(input(\"number of mugs: \"))\n", + "hvalue=int(input(\"number of hats: \"))\n", + "bvalue=int(input(\"number of books: \"))\n", + "kvalue=int(input(\"number of keychains: \"))" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": {}, + "outputs": [], + "source": [ + "inventory[\"t-shirt\"] = tvalue #[] adds a new dictonary input = to the value input on above cell\n", + "inventory[\"mug\"] = mvalue\n", + "inventory[\"hat\"] = hvalue\n", + "inventory[\"book\"] = bvalue\n", + "inventory[\"keychain\"] = kvalue" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 5, 'mug': 6, 'hat': 7, 'book': 8, 'keychain': 5}" + ] + }, + "execution_count": 110, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory #double checked" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": {}, + "outputs": [], + "source": [ + "costumer_orders = set() #empty set created" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Welcome! Please choose 3 of the available products: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "print(\"Welcome! Please choose 3 of the available products:\",products)" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Pick your item: hat\n", + "Pick your item: hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Product already chosen, pick another one from the list\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Pick your item: KEYCHAIN\n", + "Pick your item: t-shirt\n" + ] + } + ], + "source": [ + "while len(costumer_orders) < 3: # limits the user input to 3\n", + " item = input(\"Pick your item: \").lower()\n", + "\n", + " if item not in products: #limits the products chosen to the list\n", + " print(\"Sorry, product not available\")\n", + " costumer_orders.add(item)\n", + "\n", + " elif item in costumer_orders: #limits duplicates\n", + " print(\"Product already chosen, pick another one from the list\")\n", + "\n", + " else: #.add picked item to orders set\n", + " costumer_orders.add(item) " + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'keychain', 'hat', 't-shirt'}\n" + ] + } + ], + "source": [ + "print(costumer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "metadata": {}, + "outputs": [], + "source": [ + "total_products_order = len(costumer_orders) #assigns the lenght of the order\n", + "total_available= len(products) #assigns the lenght of products avail\n", + "percentage_order = (total_products_order / total_available) * 100 #finds the percentage of the order itself" + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "metadata": {}, + "outputs": [], + "source": [ + "order_status = (total_products_order, percentage_order) #creates a tuple for the status of the order" + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "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(\"Order statistics:\")\n", + "print(f\"Total products ordered: {order_status[0]}\") #[0] shows the position one in the tuple\n", + "print(f\"Percentage of products ordered: {order_status[1]:.1f}%\") #[1] shows the position two in the tuple and add %\n", + " # ':.1f' limits the result to a decimal point to keep it neat" + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "metadata": {}, + "outputs": [], + "source": [ + "for product in costumer_orders:\n", + " inventory[product] -= 1 #removes one item from the inventory if present on order" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated Inventory:\n", + "t-shirt : 4\n", + "mug : 6\n", + "hat : 6\n", + "book : 8\n", + "keychain : 4\n" + ] + } + ], + "source": [ + "print(\"Updated Inventory:\")\n", + "for product in inventory: #for loop on each item on the inventory to display it on a list\n", + " print(f\"{product} : {inventory[product]}\") #{product} gets the key form the list / {inventory[product]} gets the valeu for it" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "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.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..bb67b88b 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,252 @@ "\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": 103, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] #product list" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {} # empty inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "number of t-shirts: 5\n", + "number of mugs: 6\n", + "number of hats: 7\n", + "number of books: 8\n", + "number of keychains: 5\n" + ] + } + ], + "source": [ + "tvalue=int(input(\"number of t-shirts: \")) #int() makes the input a integer\n", + "mvalue=int(input(\"number of mugs: \"))\n", + "hvalue=int(input(\"number of hats: \"))\n", + "bvalue=int(input(\"number of books: \"))\n", + "kvalue=int(input(\"number of keychains: \"))" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": {}, + "outputs": [], + "source": [ + "inventory[\"t-shirt\"] = tvalue #[] adds a new dictonary input = to the value input on above cell\n", + "inventory[\"mug\"] = mvalue\n", + "inventory[\"hat\"] = hvalue\n", + "inventory[\"book\"] = bvalue\n", + "inventory[\"keychain\"] = kvalue" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 5, 'mug': 6, 'hat': 7, 'book': 8, 'keychain': 5}" + ] + }, + "execution_count": 110, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory #double checked" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": {}, + "outputs": [], + "source": [ + "costumer_orders = set() #empty set created" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Welcome! Please choose 3 of the available products: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "print(\"Welcome! Please choose 3 of the available products:\",products)" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Pick your item: hat\n", + "Pick your item: hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Product already chosen, pick another one from the list\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Pick your item: KEYCHAIN\n", + "Pick your item: t-shirt\n" + ] + } + ], + "source": [ + "while len(costumer_orders) < 3: # limits the user input to 3\n", + " item = input(\"Pick your item: \").lower()\n", + "\n", + " if item not in products: #limits the products chosen to the list\n", + " print(\"Sorry, product not available\")\n", + " costumer_orders.add(item)\n", + "\n", + " elif item in costumer_orders: #limits duplicates\n", + " print(\"Product already chosen, pick another one from the list\")\n", + "\n", + " else: #.add picked item to orders set\n", + " costumer_orders.add(item) " + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'keychain', 'hat', 't-shirt'}\n" + ] + } + ], + "source": [ + "print(costumer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "metadata": {}, + "outputs": [], + "source": [ + "total_products_order = len(costumer_orders) #assigns the lenght of the order\n", + "total_available= len(products) #assigns the lenght of products avail\n", + "percentage_order = (total_products_order / total_available) * 100 #finds the percentage of the order itself" + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "metadata": {}, + "outputs": [], + "source": [ + "order_status = (total_products_order, percentage_order) #creates a tuple for the status of the order" + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "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(\"Order statistics:\")\n", + "print(f\"Total products ordered: {order_status[0]}\") #[0] shows the position one in the tuple\n", + "print(f\"Percentage of products ordered: {order_status[1]:.1f}%\") #[1] shows the position two in the tuple and add %\n", + " # ':.1f' limits the result to a decimal point to keep it neat" + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "metadata": {}, + "outputs": [], + "source": [ + "for product in costumer_orders:\n", + " inventory[product] -= 1 #removes one item from the inventory if present on order" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated Inventory:\n", + "t-shirt : 4\n", + "mug : 6\n", + "hat : 6\n", + "book : 8\n", + "keychain : 4\n" + ] + } + ], + "source": [ + "print(\"Updated Inventory:\")\n", + "for product in inventory: #for loop on each item on the inventory to display it on a list\n", + " print(f\"{product} : {inventory[product]}\") #{product} gets the key form the list / {inventory[product]} gets the valeu for it" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -68,7 +314,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,