Skip to content
Open

lab1 #675

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
236 changes: 234 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,243 @@
"\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": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 1}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory={}\n",
"inventory[\"t-shirt\"]=int(input(\"Please enter quantity for products:\"))\n",
"inventory"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 1, 'mug': 2}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inventory[\"mug\"]=int(input(\"Please enter quantity for products: \"))\n",
"inventory"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 1, 'mug': 2, 'hat': 3}"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inventory[\"hat\"]=int(input(\"Please enter quantity for products\"))\n",
"inventory"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inventory[\"book\"]=int(input(\"Please enter quantity for products\"))\n",
"inventory"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': '5'}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inventory[\"keychain\"]=input(input(\"Please enter quantity for products\"))\n",
"inventory"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"customer_orders=set()\n",
"customer_orders.add(input(\"Enter product 1 to order: \"))\n",
"customer_orders.add(input(\"Enter product 2 to order: \"))\n",
"customer_orders.add(input(\"Enter product 3 to order: \"))"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"customer orders: {'mug', 'hat', 't-shirt'}\n"
]
}
],
"source": [
"print(\"customer orders:\",customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"customer_orders = {\"t-shirt\", \"mug\", \"hat\"}\n",
"total_product_ordered = len(customer_orders)\n",
"x = total_product_ordered\n",
"y = len(products)\n",
"percentage = (x / y) * 100"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0 %\n"
]
}
],
"source": [
"print(\"Total Products Ordered:\", x)\n",
"print(\"Percentage of Products Ordered:\", percentage, \"%\")"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"inventory = {\n",
" \"t-shirt\": 5,\n",
" \"mug\": 4,\n",
" \"hat\": 6,\n",
" \"book\": 3,\n",
" \"keychain\": 7\n",
"}\n",
"inventory[list(inventory)[0]] -= 1\n",
"inventory[list(inventory)[1]] -= 1\n",
"inventory[list(inventory)[2]] -= 1\n",
"inventory[list(inventory)[3]] -=1\n",
"inventory[list(inventory)[4]] -=1"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t-shirt: 4\n",
"mug: 3\n",
"hat: 5\n",
"book: 3\n",
"keychain: 7\n"
]
}
],
"source": [
"print(\"t-shirt:\", inventory[\"t-shirt\"])\n",
"print(\"mug:\", inventory[\"mug\"])\n",
"print(\"hat:\", inventory[\"hat\"])\n",
"print(\"book:\", inventory[\"book\"])\n",
"print(\"keychain:\", inventory[\"keychain\"])"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (339777499.py, line 1)",
"output_type": "error",
"traceback": [
" \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[21]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mgit status\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m invalid syntax\n"
]
}
],
"source": [
"git status\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +300,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down