From bd41e92784e6717e20c5614ef82a6e187d65709d Mon Sep 17 00:00:00 2001 From: lervindelarosa-gif Date: Tue, 15 Sep 2026 16:14:34 +0200 Subject: [PATCH 1/2] wk1lab1 done --- lab-python-data-structures.ipynb | 139 ++++++++++++++++++++++++++++++- 1 file changed, 136 insertions(+), 3 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..6e9d7681 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,13 +50,146 @@ "\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": [ + "# Define a list called products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# Create an empty dictionary\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Ask the user to input the quantity of each product available in the inventory.\n", + "# I used a for loop since its designed to automatically step through every item in a list from start to finish, until every product in the list has been processed!\n", + "\n", + "for item in products:\n", + " qty = int(input(f\"Enter quantity for {item}: \"))\n", + " inventory[item] = qty" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Create an empty set called customer_orders.\n", + "# set() function is the only way to create an empty set otherwise it would be a dictionary\n", + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Ask the user to input the name of three products that a customer wants to order (from those in the products list)\n", + "# Repeat an action 3 times (asking the user for a product).\n", + "# Add each user input into your customer_orders set.\n", + "# append() is specifically for lists, while .add() is specifically for sets.\n", + "# Note I check that I could also use A while loop with a counter and seems more clean but I havent understood this complete yet\n", + "\n", + "order1 = input(\"Enter first product: \")\n", + "customer_orders.add(order1)\n", + "\n", + "order2 = input(\"Enter second product: \")\n", + "customer_orders.add(order2)\n", + "\n", + "order3 = input(\"Enter third product: \")\n", + "customer_orders.add(order3)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(\"Products in customer orders:\", customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# I need to calculate two numbers and store them in a tuple named order_status.\n", + "# What percentage of the catalog categories did the customer order?\" (3/5 times 100 = 60\\%$).\n", + "total_ordered = len(customer_orders)\n", + "percentage_ordered = (len(customer_orders) / len(products)) * 100" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Store these statistics in a tuple called order_status.\n", + "# Creating a tuple in Python is as simple as putting comma-separated values inside parentheses ().\n", + "order_status = (total_ordered, percentage_ordered)\n", + "print(order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Update the inventory by subtracting 1 from the quantity of each product. Modify the inventory dictionary accordingly.\n", + "for product in customer_orders:\n", + " inventory[product] = inventory[product] - 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Print the updated inventory, displaying the quantity of each product on separate lines..\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -68,7 +201,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4, From a7bca6baf6aa4d80d2f3b7913aa75d4dc673d2e0 Mon Sep 17 00:00:00 2001 From: lervindelarosa-gif Date: Tue, 15 Sep 2026 16:38:07 +0200 Subject: [PATCH 2/2] wk1lab1 done --- ...ab-python-data-structures-checkpoint.ipynb | 209 ++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 .ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb 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..6e9d7681 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,209 @@ +{ + "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": 1, + "metadata": {}, + "outputs": [], + "source": [ + "# Define a list called products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# Create an empty dictionary\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Ask the user to input the quantity of each product available in the inventory.\n", + "# I used a for loop since its designed to automatically step through every item in a list from start to finish, until every product in the list has been processed!\n", + "\n", + "for item in products:\n", + " qty = int(input(f\"Enter quantity for {item}: \"))\n", + " inventory[item] = qty" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Create an empty set called customer_orders.\n", + "# set() function is the only way to create an empty set otherwise it would be a dictionary\n", + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Ask the user to input the name of three products that a customer wants to order (from those in the products list)\n", + "# Repeat an action 3 times (asking the user for a product).\n", + "# Add each user input into your customer_orders set.\n", + "# append() is specifically for lists, while .add() is specifically for sets.\n", + "# Note I check that I could also use A while loop with a counter and seems more clean but I havent understood this complete yet\n", + "\n", + "order1 = input(\"Enter first product: \")\n", + "customer_orders.add(order1)\n", + "\n", + "order2 = input(\"Enter second product: \")\n", + "customer_orders.add(order2)\n", + "\n", + "order3 = input(\"Enter third product: \")\n", + "customer_orders.add(order3)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(\"Products in customer orders:\", customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# I need to calculate two numbers and store them in a tuple named order_status.\n", + "# What percentage of the catalog categories did the customer order?\" (3/5 times 100 = 60\\%$).\n", + "total_ordered = len(customer_orders)\n", + "percentage_ordered = (len(customer_orders) / len(products)) * 100" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Store these statistics in a tuple called order_status.\n", + "# Creating a tuple in Python is as simple as putting comma-separated values inside parentheses ().\n", + "order_status = (total_ordered, percentage_ordered)\n", + "print(order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Update the inventory by subtracting 1 from the quantity of each product. Modify the inventory dictionary accordingly.\n", + "for product in customer_orders:\n", + " inventory[product] = inventory[product] - 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Print the updated inventory, displaying the quantity of each product on separate lines..\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:base] *", + "language": "python", + "name": "conda-base-py" + }, + "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.9" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}