Skip to content
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
76 changes: 0 additions & 76 deletions lab-python-data-structures.ipynb

This file was deleted.

205 changes: 205 additions & 0 deletions lab_data_structures.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "a4b3c936",
"metadata": {},
"outputs": [],
"source": [
"# Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5d2e1c8c",
"metadata": {},
"outputs": [],
"source": [
"# Create an empty dictionary called `inventory`.\n",
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f44a5512",
"metadata": {},
"outputs": [],
"source": [
"# Ask the user to input the quantity of each product available in the inventory.\n",
"# Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n",
"\n",
"for product in products:\n",
" quantity = int(input(f\"Enter the quantity for {product} in inventory: \"))\n",
" inventory [product] = quantity"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "1660ee10",
"metadata": {},
"outputs": [],
"source": [
"# Create an empty set called `customer_orders`.\n",
"\n",
"customer_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "625ff5e1",
"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",
"# meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". \n",
"# Add each product name to the `customer_orders` set.\n",
"\n",
"for i in range (3):\n",
" order = input(f\"Enter product {i+1} to order: \")\n",
" if order in products:\n",
" customer_orders.add(order)\n",
" else:\n",
" print(\"Product not available.\")\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "84015cd9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Customer Orders: {'mug', 'hat', 't-shirt'}\n"
]
}
],
"source": [
"# Print the products in the `customer_orders` set.\n",
"\n",
"print(\"Customer Orders:\", customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "c380f313",
"metadata": {},
"outputs": [],
"source": [
"#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",
"total_products_ordered = len(customer_orders)\n",
"Percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"order_status = (total_products_ordered , Percentage_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "0f981fa3",
"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 the order statistics using the following format:\n",
"# ```\n",
"# Order Statistics:\n",
"# Total Products Ordered: <total_products_ordered>\n",
"# Percentage of Products Ordered: <percentage_ordered>% \n",
"# ```\n",
"\n",
"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": 10,
"id": "a2f04d18",
"metadata": {},
"outputs": [],
"source": [
"# Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n",
"\n",
"\n",
"for product in customer_orders:\n",
" if product in inventory:\n",
" inventory[product] -= 1\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "c8ef583f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Updated Inventory:\n",
"t-shirt: 4\n",
"mug: 5\n",
"hat: 3\n",
"book: 8\n",
"keychain: 10\n"
]
}
],
"source": [
"# Print the updated inventory, displaying the quantity of each product on separate lines.\n",
"print(\"\\nUpdated Inventory:\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"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.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}