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
159 changes: 159 additions & 0 deletions Lab_1Data_Structures.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"source": [
"#1 List\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"#2 Empty dict\n",
"inventory = {}\n",
"\n",
"#3 User input\n",
"for i in products:\n",
" quantity = int(input(f\"Enter the quantity available for {i}: \"))\n",
" inventory[i] = quantity\n",
"\n",
"#4 Empty set\n",
"customer_orders = set()\n",
"\n",
"#5 User input\n",
"for i in range(3):\n",
" order = input(\"Enter the name of a product to order: \")\n",
" customer_orders.add(order)\n",
"\n",
"#6 Print\n",
"print(customer_orders)\n",
"\n",
"\n",
"#7 Calculate & statistics code & tuple\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"order_status = (total_products_ordered, percentage_ordered)\n",
"\n"
],
"metadata": {
"id": "Zt-uReucYdkE",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "ba5048a4-a3e3-470b-d132-a5d1043ee3b5"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Enter the quantity available for t-shirt: 4\n",
"Enter the quantity available for mug: 3\n",
"Enter the quantity available for hat: 4\n",
"Enter the quantity available for book: 3\n",
"Enter the quantity available for keychain: 3\n",
"Enter the name of a product to order: mug\n",
"Enter the name of a product to order: hat\n",
"Enter the name of a product to order: book\n",
"{'hat', 'mug', 'book'}\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"#8 Print number 7\n",
"print(\"Total Products Ordered:\", order_status[0])\n",
"print(\"Percentage of Products Ordered:\", order_status[1], \"%\")\n",
"\n",
"#9 Update the inventory\n",
"for i in customer_orders:\n",
" if i in inventory:\n",
" inventory[i] -= 1\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "r3g09jjOhaQr",
"outputId": "94dc7494-b16e-41b5-c2d8-6a50a6d5c5ed"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0 %\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"print(inventory)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "PHbnZzXDmTlU",
"outputId": "246ab2f1-a0f1-4eb0-e79a-9b6029d9df6e"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"{'t-shirt': 4, 'mug': 0, 'hat': 1, 'book': 0, 'keychain': 3}\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"#10 Print final code\n",
"for i, e in inventory.items():\n",
" print(i, ':', e)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "eafd1e73-3735-4c77-97f9-11213a54eefb",
"id": "fAHELqW7oEpL"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"t-shirt : 4\n",
"mug : 0\n",
"hat : 1\n",
"book : 0\n",
"keychain : 3\n"
]
}
]
}
]
}