Skip to content

lab-structures-complete #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
220 changes: 220 additions & 0 deletions LabDataStructures.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "21d53c08-fd8f-4d32-9af8-8e698f69296c",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the t-shirt quantity here: 4\n",
"Enter the mug quantity here: 6\n",
"Enter the hat quantity here: 2\n",
"Enter the book quantity here: 5\n",
"Enter the keychain quantity here: 1\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 4, 'mug': 6, 'hat': 2, 'book': 5, 'keychain': 1}\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"\n",
"for items in products: \n",
" quantity = int(input(f\"Enter the {items} quantity here: \"))\n",
" inventory[items] = quantity\n",
"\n",
"print(inventory)\n",
"\n",
"### inventory[\"t-shirt\"] = int(input(\"Enter quantity for t-shirt: \"))\n",
"### inventory[\"mug\"] = int(input(\"Enter quantity for mug: \"))\n",
"### inventory[\"hat\"] = int(input(\"Enter quantity for hat: \"))\n",
"### inventory[\"book\"] = int(input(\"Enter quantity for book: \"))\n",
"### inventory[\"keychain\"] = int(input(\"Enter quantity for keychain: \"))\n",
"\n",
"### the above is an example of taking the inventory without using for loops"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "e7ceec06-871b-4104-b086-55997d1aadc4",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the name of product 1: t-shirt\n",
"Enter the name of product 2: hat\n",
"Enter the name of product 3: mug\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'hat', 't-shirt', 'mug'}\n"
]
}
],
"source": [
"customer_orders = set()\n",
"\n",
"for i in range(3):\n",
" product_name = input(f\"Enter the name of product {i + 1}: \")\n",
" customer_orders.add(product_name)\n",
"\n",
"print(customer_orders)\n",
"\n",
"\n",
"### product1 = input(\"Enter product 1: \")\n",
"### product2 = input(\"Enter product 2: \")\n",
"### product3 = input(\"Enter product 3: \")\n",
"\n",
"### customer_orders.add(product1)\n",
"### customer_orders.add(product2)\n",
"### customer_orders.add(product3)\n",
"\n",
"### again, the idea of inputting the data without using for loops\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "0fc4d511-99f0-4270-87a2-78ba2273ddaf",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n"
]
}
],
"source": [
"total_products_ordered = len(customer_orders)\n",
"print(total_products_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "2e73b527-1a37-4f99-98db-05c285596ca4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"60.0\n"
]
}
],
"source": [
"percent_ordered = (total_products_ordered / len(products)) * 100\n",
"print(percent_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "43ba81dc-019b-458a-b90f-7d7f370823b3",
"metadata": {},
"outputs": [],
"source": [
"order_status = (total_products_ordered, percent_ordered) \n",
"\n",
"### first tuple I think I've used? "
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "67a34627-63d3-41eb-af39-9242c72f9237",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics: (3, 60.0)\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0 %\n"
]
}
],
"source": [
"print(\"Order Statistics: \" , order_status)\n",
"print(\"Total Products Ordered: \" , order_status[0])\n",
"print(\"Percentage of Products Ordered: \" , order_status[1] , \"%\")"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "50a1c167-fa69-433f-a792-e81a55704097",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t-shirt: 3\n",
"mug: 5\n",
"hat: 1\n",
"book: 5\n",
"keychain: 1\n"
]
}
],
"source": [
"for item in customer_orders:\n",
" inventory[item] -= 1\n",
"\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e76d6340-c281-4d46-83b4-72697e57f636",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}