Skip to content
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
47 changes: 46 additions & 1 deletion lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,51 @@
"\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": [
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory={}\n",
"for product in products:\n",
" quantity = input(f\"Enter the quantity for {product}: \")\n",
" inventory[product] = int(quantity)\n",
"\n",
"customer_orders=set() \n",
"\n",
"while len(customer_orders)<3:\n",
" product=input(\"enter the name of a product you'd like to order: \").strip()\n",
" if product in products:\n",
" customer_orders.add(product)\n",
" else:\n",
" print(\"That's not a valid product. Please choose from the list.\")\n",
" print(\"Available products:\", \", \".join(products))\n",
" \n",
"print(\"customer order: \", customer_orders) \n",
"\n",
"total_products_ordered=len(customer_orders)\n",
"percentage_products_ordered=(total_products_ordered/len(products))*100\n",
"ordered_status=(total_products_ordered, percentage_products_ordered) \n",
"print(\"\"\"Order Statistics:\n",
" Total Products Ordered: <total_products_ordered>\n",
" Percentage of Products Ordered: <percentage_ordered>% \n",
" \"\"\")\n",
"\n",
"for product in customer_orders:\n",
" if product in inventory:\n",
" inventory[product]=max(0, inventory[product]-1)\n",
"print(\"Update inventory: \", inventory) \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -68,7 +113,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down