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
115 changes: 113 additions & 2 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,122 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "859b2db6",
"metadata": {},
"outputs": [],
"source": [
"def initialize_inventory(products):\n",
" inventory = {}\n",
" for product in products:\n",
" quantity = int(input(f\"Enter the quantity of {product} available in the inventory: \"))\n",
" inventory[product] = quantity\n",
" return inventory"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "afe647b6",
"metadata": {},
"outputs": [],
"source": [
"def get_customer_orders():\n",
" customer_orders = set()\n",
" while True:\n",
" product_name = input(\"Enter a product name (or 'done' to finish): \")\n",
" if product_name.lower() == \"done\":\n",
" break\n",
" customer_orders.add(product_name)\n",
" return customer_orders\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "cdc0e424",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "'return' outside function (2417354517.py, line 5)",
"output_type": "error",
"traceback": [
"\u001b[0;36m Cell \u001b[0;32mIn[15], line 5\u001b[0;36m\u001b[0m\n\u001b[0;31m return inventory\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m 'return' outside function\n"
]
}
],
"source": [
"def update_inventory(Customer_orders, inventory):\n",
" for products in Customer_orders:\n",
" if products in inventory:\n",
" inventory[products] -= 1\n",
"return inventory \n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "aef83c40",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "expected ':' (4091173692.py, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m Cell \u001b[0;32mIn[9], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m def calculate_order_statistics (customer_orders, products)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m expected ':'\n"
]
}
],
"source": [
"def calculate_order_statistics (customer_orders, products)\n",
" total_items = len(customer_orders)\n",
" available_items = sum(1 for product in customer_order if product in products\n",
" unavailable_items = total_items - available_items)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "10ec1958",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "unterminated string literal (detected at line 3) (1798483224.py, line 3)",
"output_type": "error",
"traceback": [
"\u001b[0;36m Cell \u001b[0;32mIn[13], line 3\u001b[0;36m\u001b[0m\n\u001b[0;31m print(f\"Total items ordered:{order_statistics['total_items]}\")\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m unterminated string literal (detected at line 3)\n"
]
}
],
"source": [
"def print_order_statistics(order_statistics):\n",
" print(\"order_statistics\")\n",
" print(f\"Total items ordered:{order_statistics['total_items]}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "be0ed016",
"metadata": {},
"outputs": [],
"source": [
"def print_updated_inventory(inventory):\n",
" print(\"updated_invetory\")\n",
" for product, quantity in inventory.items()\n",
" print(f\"{product}: {quantity}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +172,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down