Skip to content

Lab Answers Day 3 #464

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 2 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
Binary file added .DS_Store
Binary file not shown.
246 changes: 242 additions & 4 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"cell_type": "markdown",
"id": "3851fcd1-cf98-4653-9c89-e003b7ec9400",
"id": "5a4b9d59-d3a6-46dd-a714-d6cd466deb5b",
"metadata": {},
"source": [
"## Exercise: Managing Customer Orders Optimized\n",
Expand All @@ -37,13 +37,251 @@
"\n",
"3. Instead of updating the inventory by subtracting 1 from the quantity of each product, only do it for the products that were ordered (those in \"customer_orders\")."
]
},
{
"cell_type": "code",
"execution_count": 139,
"id": "c1d5935f-266a-4c83-8a4f-bc12d27f409c",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Amount of tshirts available: 5\n",
"Amount of mugs available: 5\n",
"Amount of hats available: 5\n",
"Amount of books available: 5\n",
"Amount of keychains available: 5\n"
]
}
],
"source": [
"products = [\"tshirts\", \"mugs\", \"hats\", \"books\", \"keychains\"]\n",
"inventory = {}\n",
"\n",
"for items in products:\n",
" inventory[items] = int(input(f\"Amount of {items} available:\"))"
]
},
{
"cell_type": "code",
"execution_count": 140,
"id": "f4c87915-45ef-4934-8f82-1c52d62139b7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'tshirts': 5, 'mugs': 5, 'hats': 5, 'books': 5, 'keychains': 5}\n"
]
}
],
"source": [
"type(inventory)\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 141,
"id": "e56fc9b6-00b9-451f-a996-8995323d7f3e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"set"
]
},
"execution_count": 141,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"customer_order = set()\n",
"type(customer_order)"
]
},
{
"cell_type": "code",
"execution_count": 142,
"id": "47f18003-44f8-4f9e-b784-f6d6f8f5f018",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the name of the Product#1 you want: mugs\n",
"Enter the name of the Product#2 you want: hats\n",
"Enter the name of the Product#3 you want: tshirts\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"These are the products you ordered: {'mugs', 'hats', 'tshirts'}\n"
]
}
],
"source": [
"for product in [\"Product#1\", \"Product#2\", \"Product#3\"]:\n",
" new_order = input(f\"Enter the name of the {product} you want: \")\n",
" customer_order.add(new_order)\n",
"print(\"These are the products you ordered:\", customer_order)"
]
},
{
"cell_type": "code",
"execution_count": 143,
"id": "ca794f04-f14e-4ef1-beb5-6891b951e923",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Do you want another product? no\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"You need to add more products to move forward\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Do you want another product? yes\n"
]
}
],
"source": [
"new_products = input(\"Do you want another product?\")\n",
"while new_products == \"no\":\n",
" print(\"You need to add more products to move forward\")\n",
" new_products = input(\"Do you want another product?\")"
]
},
{
"cell_type": "code",
"execution_count": 144,
"id": "9ff67eb2-3c19-48cd-a453-0709bfddbbd7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Products Ordered: 3\n"
]
}
],
"source": [
"total_products_ordered = len(customer_order)\n",
"print(\"Total Products Ordered:\", len(customer_order))"
]
},
{
"cell_type": "code",
"execution_count": 145,
"id": "835b0f57-971f-410c-821c-cd30c1d0bf17",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Available Products: 25\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 12.0 %\n"
]
}
],
"source": [
"total_available_products = sum(inventory.values())\n",
"print(\"Total Available Products:\",total_available_products)\n",
"print(\"Total Products Ordered: \", total_products_ordered)\n",
"percentage_ordered = (total_products_ordered / total_available_products)*100\n",
"print(\"Percentage of Products Ordered:\", percentage_ordered,\"%\")"
]
},
{
"cell_type": "code",
"execution_count": 146,
"id": "ab8a7738-de70-4a43-be1d-53715d59e1cf",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Products Ordered:: 3\n",
"Total Available Products: 25\n"
]
}
],
"source": [
"order_status = (total_products_ordered, total_available_products)\n",
"print(\"Total Products Ordered::\", order_status[0])\n",
"print(\"Total Available Products:\", order_status[1])"
]
},
{
"cell_type": "code",
"execution_count": 147,
"id": "4411799f-3fe0-40f6-84c1-fe6b6933ada6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'tshirts': 5, 'mugs': 5, 'hats': 5, 'books': 5, 'keychains': 5}"
]
},
"execution_count": 147,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inventory"
]
},
{
"cell_type": "code",
"execution_count": 148,
"id": "c3cb13e9-66e6-4c14-be10-4492e9fa8aa3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"New Updated Inventory {'tshirts': 4, 'mugs': 4, 'hats': 4, 'books': 5, 'keychains': 5}\n"
]
}
],
"source": [
"for item in customer_order:\n",
" inventory[item] -= 1\n",
"\n",
"print(\"New Updated Inventory\", inventory)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "anaconda-panel-2023.05-py310",
"language": "python",
"name": "python3"
"name": "conda-env-anaconda-panel-2023.05-py310-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -55,7 +293,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down