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
100 changes: 99 additions & 1 deletion lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,104 @@
"\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": 1,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the quantity available of t-shirt please: 50\n",
"Enter the quantity available of mug please: 50\n",
"Enter the quantity available of hat please: 60\n",
"Enter the quantity available of book please: 40\n",
"Enter the quantity available of keychain please: 30\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"\n",
"for product in products:\n",
" quantity = int(input(f\"Enter the quantity available of {product} please: \"))\n",
" inventory[product] = quantity"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['t-shirt', 'mug', 'hat', 'book', 'keychain']\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Please enter a product out of the previous list: book\n",
"Please enter a product out of the previous list: hat\n",
"Please enter a product out of the previous list: mug\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'hat', 'book', 'mug'}\n",
"3\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0%\n",
"t-shirt: 49\n",
"mug: 49\n",
"hat: 59\n",
"book: 39\n",
"keychain: 29\n"
]
}
],
"source": [
"customer_orders = set()\n",
"print(products)\n",
"\n",
"for i in range(3):\n",
" products_ordered = input('Please enter a product out of the previous list: ')\n",
" customer_orders.add(products_ordered) \n",
" \n",
"print(customer_orders)\n",
"total_products_ordered = len(customer_orders) \n",
"print(total_products_ordered) \n",
"\n",
"float_products_ordered = float(total_products_ordered)\n",
"porcentage_ordered = float_products_ordered/5*100\n",
"order_status = (total_products_ordered, porcentage_ordered)\n",
"\n",
"print('Order Statistics:')\n",
"print(f'Total Products Ordered: {total_products_ordered}') \n",
"print(f'Percentage of Products Ordered: {porcentage_ordered}%')\n",
"\n",
"for product_name in inventory:\n",
" inventory[product_name] -= 1\n",
"\n",
"for product_name, quantity in inventory.items():\n",
" print(f\"{product_name}: {quantity}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -68,7 +166,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down