Skip to content

data_structure_lab_day1_second_time #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
53 changes: 53 additions & 0 deletions .ipynb_checkpoints/dataLab_day1-checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

#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.
#Follow the steps below to complete the exercise:

#1. Define a list called `products` that contains the following items: "t-shirt", "mug", "hat", "book", "keychain".
products = ["t-shirt", "mug", "hat", "book", "keychain"]

#2. Create an empty dictionary called `inventory`.
inventory={}

#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.#
for product in products:
num = float(input(f'Enter a quantity for {product}:'))
inventory[product]=num #dictionary enters all the values for each key provided
print('The dicctionary called inventory is:' ,inventory)

#4. Create an empty set called `customer_orders`.
customer_orders = set()
#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.

for i in range(3):
product = input("Enter the name of a product to order (t-shirt, mug, hat, book, keychain): ")
if product in products:
customer_orders.add(product)
else:
print("Invalid product. Please choose from the available products.")

#6. Print the products in the `customer_orders` set.
print("Customer orders:", customer_orders)

#7. Calculate the following order statistics:
#- Total Products Ordered: The total number of products in the `customer_orders` set.
total_customers_ordered = len(customer_orders)
#- Percentage of Products Ordered: The percentage of products ordered compared to the total available products.
percentage_ordered= (total_customers_ordered/len(products))
#Store these statistics in a tuple called `order_status`.
order_status =(total_customers_ordered,percentage_ordered)

#8. Print the order statistics using the following format:
#Order Statistics:
#Total Products Ordered: <total_products_ordered>
#Percentage of Products Ordered: <percentage_ordered>%
print('The total of customers ordered:' , total_customers_ordered)
print('The percentage is: ', percentage_ordered)

#9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.
#inventory=inventory[:-1]


#10. Print the updated inventory, displaying the quantity of each product on separate lines.
#print(inventory)
#Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations.
328 changes: 328 additions & 0 deletions .ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
{
"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",
" products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"#2. Create an empty dictionary called `inventory`.\n",
"inventory_products={}\n",
"\n",
"#3. Ask the user to input the quantity of each product available in the inventory.\n",
"\n",
"product_inventory_ts=int(input('Please, insert the quantity for mug: '))\n",
"product_inventory_mug=int(input('Please, insert the quantity for mug: '))\n",
"product_inventory_hat=int(input('Please, insert the quantity for hat: '))\n",
"product_inventory_book=int(input('Please, insert the quantity for mug: '))\n",
"product_inventory_keychain=int(input('Please, insert the quantity for mug: '))\n",
"\n",
"#Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n",
"#products_name={}\n",
"\n",
"#4. Create an empty set called `customer_orders`.\n",
"customer_orders = set()\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": []
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"#1. Define a list called products that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n",
"\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"#2. Create an empty dictionary called inventory. inventory_products={}\n",
"inventory={}"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Please, insert the quantity for ts: 4\n",
"Please, insert the quantity for mug: 5\n",
"Please, insert the quantity for hat: 6\n",
"Please, insert the quantity for book: 72\n",
"Please, insert the quantity for keychain: 2\n"
]
}
],
"source": [
"##### 3. Ask the user to input the quantity of each product available in the inventory.\n",
"product_inventory_ts=int(input('Please, insert the quantity for ts: '))\n",
"product_inventory_mug=int(input('Please, insert the quantity for mug: ')) \n",
"product_inventory_hat=int(input('Please, insert the quantity for hat: ')) \n",
"product_inventory_book=int(input('Please, insert the quantity for book: ')) \n",
"product_inventory_keychain=int(input('Please, insert the quantity for keychain: '))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 72, 'keychain': 2}\n"
]
}
],
"source": [
"#Use the product names from the products list as keys in the inventory dictionary and assign the respective quantities as values. \n",
"#products_name={}\n",
"inventory[\"t-shirt\"] = product_inventory_ts\n",
"inventory[\"mug\"] = product_inventory_mug\n",
"inventory[\"hat\"] = product_inventory_hat\n",
"inventory[\"book\"] = product_inventory_book\n",
"inventory[\"keychain\"] = product_inventory_keychain\n",
"print(inventory)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#4. Create an empty set called `customer_orders`.\n",
"customer_orders = set()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
" #5 Ask the user to input the name of three products that a customer wants to order \n",
" #(from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\".\n",
" #Add each product name to the customer_orders set."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Please, enter from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\" hat\n",
"Please, enter from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\" book\n",
"Please, enter from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\" mug\n"
]
}
],
"source": [
"product_1 = input('Please, enter from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\"')\n",
"product_2 = input('Please, enter from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\"')\n",
"product_3 = input('Please, enter from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\"')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'hat', 'book', 'mug'}\n"
]
}
],
"source": [
"customer_orders = set([product_1, product_2, product_3])"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The customer order is: {'hat', 'book', 'mug'}\n"
]
}
],
"source": [
"#6. Print the products in the customer_orders set.\n",
"print('The customer order is:' , customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The total number of products: 3\n",
"The percentage of products ordered: 0.6\n"
]
}
],
"source": [
"#7. Calculate the following order statistics:\n",
"#Total Products Ordered: The total number of products in the customer_orders set.\n",
"total_products_ordered = len(customer_orders)\n",
"print('The total number of products: ', total_products_ordered)\n",
"#Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n",
"percentage_ordered = total_products_ordered/len(inventory)\n",
"print('The percentage of products ordered:', percentage_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"#Store these statistics in a tuple called order_status.\n",
"order_status = (total_products_ordered, percentage_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total products ordered: 3\n",
"The percentage of products ordered: 0.6\n"
]
}
],
"source": [
"#8. Print the order statistics using the following format:\n",
"print('Total products ordered:', total_products_ordered)\n",
"print('The percentage of products ordered:', percentage_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 4, 'mug': 5, 'hat': 5, 'book': 72, 'keychain': 2}\n",
"{'t-shirt': 4, 'mug': 4, 'hat': 4, 'book': 71, 'keychain': 2}\n"
]
}
],
"source": [
"#9. Update the inventory by subtracting 1 from the quantity of each product. Modify the inventory dictionary accordingly.\n",
"print(inventory)\n",
"customer_order_list = list(customer_orders)\n",
"inventory[customer_order_list[0]] = inventory[customer_order_list[0]] - 1\n",
"inventory[customer_order_list[1]] = inventory[customer_order_list[1]] - 1\n",
"inventory[customer_order_list[2]] = inventory[customer_order_list[2]] - 1\n",
"print(inventory)"
]
},
{
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading