Skip to content

lab complete #452

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 1 commit into
base: main
Choose a base branch
from
Open
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
80 changes: 79 additions & 1 deletion lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,84 @@
"\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": 9,
"id": "c47155b7-2836-4e37-8842-70d58a8eaecb",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the quantity of t-shirt: 1\n",
"Enter the quantity of mug: 2\n",
"Enter the quantity of hat: 3\n",
"Enter the quantity of book: 4\n",
"Enter the quantity of keychain: 5\n",
"Enter the name of a product that the customer wants : ['t-shirt', 'mug', 'hat', 'book', 'keychain'] mug\n",
" Want to do another purchase, answser : yes or no no\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is the customer order : {'mug'}\n",
"Order Statistics:\n",
"Total Products Ordered: 1.\n",
"Percentage of Products Ordered: 6.67%. \n",
"This is the inventory after customer order :\n",
"t-shirt : 1\n",
"mug : 1\n",
"hat : 3\n",
"book : 4\n",
"keychain : 5\n",
"{'mug'}\n"
]
}
],
"source": [
"list_products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"customer_orders = set()\n",
"customer_status = True\n",
"\n",
"for product in list_products :\n",
" quantity = int(input(f\"Enter the quantity of {product}: \"))\n",
" inventory[product] = quantity\n",
" \n",
"while customer_status == True:\n",
" customer_orders.add(input(f\"Enter the name of a product that the customer wants : {list_products}\"))\n",
" customer_answer = (input(f\" Want to do another purchase, answser : yes or no\"))\n",
" if customer_answer == \"yes\" :\n",
" customer_status = True\n",
" else :\n",
" customer_status = False\n",
" break\n",
"\n",
"total_prod_ordered = len(customer_orders)\n",
"total_inventory = sum(inventory.values())\n",
"percentage_products_ordered = (total_prod_ordered / total_inventory)*100\n",
"order_status = (total_prod_ordered, percentage_products_ordered) \n",
"\n",
"for product in customer_orders :\n",
" if product in inventory and inventory[product] > 0:\n",
" inventory[product] -= 1\n",
" \n",
"print(f\"This is the customer order : {customer_orders}\")\n",
"print(\"Order Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}.\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%. \")\n",
"\n",
"print(f\"This is the inventory after customer order :\")\n",
"for product, quantity in inventory.items():\n",
" print (f\"{product} : {quantity}\") \n",
"print(customer_orders)"
]
}
],
"metadata": {
Expand All @@ -55,7 +133,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down