Skip to content
Open

lab1 #735

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
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"python-envs.pythonProjects": [
{
"path": ".",
"envManager": "ms-python.python:system",
"packageManager": "ms-python.python:pip"
}
]
}
52 changes: 52 additions & 0 deletions Untitled-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"c:\Users\MEL\Downloads\DATA\laboratorio1\Untitled-1.py"

# Step 1: Define the products list
from doctest import master

products = ["t-shirt", "mug", "hat", "book", "keychain"]

# Step 2: Create an empty inventory dictionary
inventory = {}

# Step 3: Ask the user for the quantity of each product
for product in products:
quantity = int(input(f"Enter the quantity of {product}: "))
inventory[product] = quantity

# Step 4: Create an empty set for customer orders
customer_orders = set()

# Step 5: Ask the user for the products they want to order
for i in range(3): # Assuming the user can order up to 3 products
order = input(f"Enter product {i+1} to order: ")
customer_orders.add(order)

# Step 6: Print the customer orders
print("\nCustomer Orders:", customer_orders)

# Step 7: Calculate order statistics
total_products_ordered = len(customer_orders)
percentage_ordered = (total_products_ordered / len(products)) * 100

# Store in a tuple
order_status = (total_products_ordered, percentage_ordered)

# Step 8: Print the order statistics
print("\nOrder Statistics:")
print(f"Total Products Ordered: {order_status[0]}")
print(f"Percentage of Products Ordered: {order_status[1]}%")

# Step 9: Update inventory by subtracting 1 from each product
for product in inventory:
inventory[product] -= 1

# Step 10: Print the updated inventory
print("\nUpdated Inventory:")
for product, quantity in inventory.items():
print(f"{product}: {quantity}")

git add .

git commit -m "Solved lab"

git push origin master
52 changes: 52 additions & 0 deletions Untitled-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"c:\Users\MEL\Downloads\DATA\laboratorio1\Untitled-1.py"

# Step 1: Define the products list
from doctest import master

products = ["t-shirt", "mug", "hat", "book", "keychain"]

# Step 2: Create an empty inventory dictionary
inventory = {}

# Step 3: Ask the user for the quantity of each product
for product in products:
quantity = int(input(f"Enter the quantity of {product}: "))
inventory[product] = quantity

# Step 4: Create an empty set for customer orders
customer_orders = set()

# Step 5: Ask the user for the products they want to order
for i in range(3): # Assuming the user can order up to 3 products
order = input(f"Enter product {i+1} to order: ")
customer_orders.add(order)

# Step 6: Print the customer orders
print("\nCustomer Orders:", customer_orders)

# Step 7: Calculate order statistics
total_products_ordered = len(customer_orders)
percentage_ordered = (total_products_ordered / len(products)) * 100

# Store in a tuple
order_status = (total_products_ordered, percentage_ordered)

# Step 8: Print the order statistics
print("\nOrder Statistics:")
print(f"Total Products Ordered: {order_status[0]}")
print(f"Percentage of Products Ordered: {order_status[1]}%")

# Step 9: Update inventory by subtracting 1 from each product
for product in inventory:
inventory[product] -= 1

# Step 10: Print the updated inventory
print("\nUpdated Inventory:")
for product, quantity in inventory.items():
print(f"{product}: {quantity}")

git add .

git commit -m "Solved lab"

git push origin master
61 changes: 59 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,68 @@
"\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": null,
"metadata": {},
"outputs": [],
"source": [
"# Step 1: Define the products list\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"# Step 2: Create an empty inventory dictionary\n",
"inventory = {}\n",
"\n",
"# Step 3: Ask the user for the quantity of each product\n",
"for product in products:\n",
" quantity = int(input(f\"Enter the quantity of {product}: \"))\n",
" inventory[product] = quantity\n",
"\n",
"# Step 4: Create an empty set for customer orders\n",
"customer_orders = set()\n",
"\n",
"# Step 5: Ask the user for the products they want to order\n",
"for i in range(3):\n",
" order = input(f\"Enter product {i+1} to order: \")\n",
" customer_orders.add(order)\n",
"\n",
"# Step 6: Print the customer orders\n",
"print(\"\\nCustomer Orders:\", customer_orders)\n",
"\n",
"# Step 7: Calculate order statistics\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"\n",
"# Store in a tuple\n",
"order_status = (total_products_ordered, percentage_ordered)\n",
"\n",
"# Step 8: Print the order statistics\n",
"print(\"\\nOrder Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n",
"\n",
"# Step 9: Update inventory by subtracting 1 from each product\n",
"for product in inventory:\n",
" inventory[product] -= 1\n",
"\n",
"# Step 10: Print the updated inventory\n",
"print(\"\\nUpdated Inventory:\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +125,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.10.20"
}
},
"nbformat": 4,
Expand Down
133 changes: 133 additions & 0 deletions lab-python-data-structureslab1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"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: <total_products_ordered>\n",
" Percentage of Products Ordered: <percentage_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": null,
"metadata": {},
"outputs": [],
"source": [
"# Step 1: Define the products list\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"# Step 2: Create an empty inventory dictionary\n",
"inventory = {}\n",
"\n",
"# Step 3: Ask the user for the quantity of each product\n",
"for product in products:\n",
" quantity = int(input(f\"Enter the quantity of {product}: \"))\n",
" inventory[product] = quantity\n",
"\n",
"# Step 4: Create an empty set for customer orders\n",
"customer_orders = set()\n",
"\n",
"# Step 5: Ask the user for the products they want to order\n",
"for i in range(3):\n",
" order = input(f\"Enter product {i+1} to order: \")\n",
" customer_orders.add(order)\n",
"\n",
"# Step 6: Print the customer orders\n",
"print(\"\\nCustomer Orders:\", customer_orders)\n",
"\n",
"# Step 7: Calculate order statistics\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"\n",
"# Store in a tuple\n",
"order_status = (total_products_ordered, percentage_ordered)\n",
"\n",
"# Step 8: Print the order statistics\n",
"print(\"\\nOrder Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n",
"\n",
"# Step 9: Update inventory by subtracting 1 from each product\n",
"for product in inventory:\n",
" inventory[product] -= 1\n",
"\n",
"# Step 10: Print the updated inventory\n",
"print(\"\\nUpdated Inventory:\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.10.20"
}
},
"nbformat": 4,
"nbformat_minor": 4
}