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
124 changes: 123 additions & 1 deletion lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,128 @@
"\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": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please, enter the avaliable quantity of each product\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"t-shirt: 34\n",
"mug: 6\n",
"hat: 2\n",
"book: 4\n",
"keychain: 7\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The following products are availiable in the stock: {'t-shirt': 34, 'mug': 6, 'hat': 2, 'book': 4, 'keychain': 7}\n",
"To complete your order, enter three product name separated by space\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
" hat t-shirt book\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Your order contains this products: {'t-shirt', 'hat', 'book'}\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"print(\"Please, enter the avaliable quantity of each product\")\n",
"for i in products:\n",
" inp = int(input(\"{}: \".format(i)))\n",
" inventory[i] = inp\n",
"print(\"The following products are availiable in the stock:\", inventory)\n",
"customer_orders = {} \n",
"print(\"To complete your order, enter three product name separated by space\")\n",
"\n",
"item_1, item_2, item_3 = input(\" \").split()\n",
"customer_orders = {item_1, item_2, item_3}\n",
"print(\"Your order contains this products:\", customer_orders)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Order Statistics**"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60%\n"
]
}
],
"source": [
"print(\"Total Products Ordered: {}\".format(len(customer_orders)))\n",
"print(\"Percentage of Products Ordered: {}%\".format(int(len(customer_orders)*100/len(products))))"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The following products are availiable in the stock: {'t-shirt': 33, 'mug': 6, 'hat': 1, 'book': 3, 'keychain': 7}\n"
]
}
],
"source": [
"for i in customer_orders:\n",
" inventory[i] = int(inventory[i]) - 1\n",
" \n",
"print(\"The following products are availiable in the stock:\", inventory) "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -68,7 +190,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.6"
}
},
"nbformat": 4,
Expand Down