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
76 changes: 74 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,83 @@
"\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": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 9, 'mug': 7, 'hat': 8, 'book': 5, 'keychain': 9}\n",
"{'hat', 'mug', 'book'}\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 7.894736842105263\n",
"Inventory Updated:\n",
"t-shirt 9\n",
"mug 6\n",
"hat 7\n",
"book 4\n",
"keychain 9\n"
]
}
],
"source": [
"produtcs = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"\n",
"inventory.fromkeys(produtcs)\n",
"x = 0\n",
"\n",
"for produtc in produtcs:\n",
" inventory[produtcs[x]] = int(input(f\"Please, enter the number of {produtcs[x]} available in the inventory:\"))\n",
" x += 1\n",
"\n",
"print(inventory)\n",
"\n",
"\n",
"customers_orders = set()\n",
"\n",
"produtcs_1 = input(\"Please, introduce the product that the costumer wants to order:\")\n",
"produtcs_2 = input(\"Please, introduce the product that the costumer wants to order:\")\n",
"produtcs_3 = input(\"Please, introduce the product that the costumer wants to order:\")\n",
"\n",
"customers_orders = {produtcs_1,produtcs_2,produtcs_3}\n",
"\n",
"print(customers_orders)\n",
"\n",
"\n",
"# Total Products Ordered\n",
"\n",
"print(\"Total Products Ordered:\",len(customers_orders))\n",
"\n",
"# Percentage of Products Ordered\n",
"\n",
"total = inventory['t-shirt'] + inventory['mug'] + inventory['hat'] + inventory['book'] + inventory['keychain']\n",
"\n",
"percentage = (len(customers_orders) * 100) / total\n",
"\n",
"\n",
"print(\"Percentage of Products Ordered:\",percentage)\n",
"\n",
"for order in customers_orders:\n",
" if order in inventory:\n",
" inventory[order] = inventory[order] - 1\n",
"\n",
"# Total Products Ordered\n",
"\n",
"print(\"Inventory Updated:\")\n",
"for prod in inventory:\n",
" print(prod,inventory[prod])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +140,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.6"
}
},
"nbformat": 4,
Expand Down