diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..1a4edece 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -9,6 +9,97 @@ "# Lab | Data Structures " ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "You can choose from these products:\n", + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "That product is not in the list. Please try again.\n", + "\n", + "The customer ordered these products:\n", + "mug\n", + "hat\n", + "t-shirt\n", + "\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0 %\n", + "\n", + "Updated Inventory:\n", + "t-shirt: 0\n", + "mug: 0\n", + "hat: 0\n", + "book: 1\n", + "keychain: 1\n" + ] + } + ], + "source": [ + "# Step 1: Create a list of products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# Step 2: Make an empty dictionary to store product quantities\n", + "inventory = {}\n", + "\n", + "# Step 3: Ask the user to enter the quantity for each product\n", + "for product in products:\n", + " quantity = input(\"How many of this product do you have in stock: \" + product + \"? \")\n", + " quantity = int(quantity) # Convert input to an integer\n", + " inventory[product] = quantity # Save it in the inventory\n", + "\n", + "# Step 4: Create a set to store what the customer wants to buy\n", + "customer_orders = -set()\n", + "\n", + "# Step 5: Ask the user to type 3 products they want to order\n", + "print(\"\\nYou can choose from these products:\")\n", + "print(products)\n", + "\n", + "while len(customer_orders) < 3:\n", + " chosen_product = input(\"Type the name of a product to order: \")\n", + " \n", + " # Check if the product is valid\n", + " if chosen_product in products:\n", + " customer_orders.add(chosen_product)\n", + " else:\n", + " print(\"That product is not in the list. Please try again.\")\n", + "\n", + "# Step 6: Show the products the customer chose\n", + "print(\"\\nThe customer ordered these products:\")\n", + "for order in customer_orders:\n", + " print(order)\n", + "\n", + "# Step 7: Calculate how many different products were ordered\n", + "total_ordered = len(customer_orders)\n", + "\n", + "# Calculate what percent of all available products were ordered\n", + "total_available = len(products)\n", + "percentage_ordered = (total_ordered / total_available) * 100\n", + "\n", + "# Save both results in a tuple\n", + "order_status = (total_ordered, percentage_ordered)\n", + "\n", + "# Step 8: Print the order statistics nicely\n", + "print(\"\\nOrder Statistics:\")\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(\"Percentage of Products Ordered:\", round(order_status[1], 2), \"%\")\n", + "\n", + "# Step 9: Update inventory by subtracting 1 from each ordered product\n", + "for item in customer_orders:\n", + " inventory[item] = inventory[item] - 1 # Take one out of stock\n", + "\n", + "# Step 10: Print the new inventory\n", + "print(\"\\nUpdated Inventory:\")\n", + "for item in inventory:\n", + " print(item + \": \" + str(inventory[item]))" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -54,7 +145,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +159,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.1" } }, "nbformat": 4,