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": 12,
"id": "3eeac03c",
"metadata": {},
"outputs": [],
"source": [
"def initialize_inventory(products):\n",
" inventory = {}\n",
"\n",
" for product in products: \n",
" amount = int(input(f\"How many products are of {product}?\"))\n",
" inventory[product] = amount\n",
" \n",
" return(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "5c9a3292",
"metadata": {},
"outputs": [],
"source": [
"def get_costumer_orders():\n",
" costumer_orders = set()\n",
" petition = \"Yes\".lower()\n",
"\n",
" while petition == \"Yes\".lower():\n",
" order = input(\"Write a product to order\")\n",
" costumer_orders.add(order)\n",
" petition = input(\"Do you want to order another product? (Yes/No)\").lower()\n",
"\n",
" return(costumer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "874892fb",
"metadata": {},
"outputs": [],
"source": [
"def update_inventory(costumer_orders,inventory):\n",
" for product in costumer_orders:\n",
" inventory[product] -= 1 \n",
" return(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "2e33efc5",
"metadata": {},
"outputs": [],
"source": [
"def calculate_order_statistics(costumer_orders,products): \n",
"\n",
" total_products_ordered = len(costumer_orders)\n",
" percentage_unique_products = total_products_ordered / len(products) * 100 \n",
" return(total_products_ordered, percentage_unique_products)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "6bdfadf1",
"metadata": {},
"outputs": [],
"source": [
"def print_order_statistics(order_statistics):\n",
" print(order_statistics)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "0ddd67f9",
"metadata": {},
"outputs": [],
"source": [
"def print_updated_inventory(inventory):\n",
" print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "62a8bde3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(2, 40.0)\n",
"{'t-shirt': 47, 'mug': 383, 'hat': 38, 'book': 298, 'keychain': 29}\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = initialize_inventory(products)\n",
"costumer_orders = get_costumer_orders()\n",
"update_inventory(costumer_orders, inventory)\n",
"order_statistics = calculate_order_statistics(costumer_orders,products)\n",
"print_order_statistics(order_statistics)\n",
"print_updated_inventory(inventory)\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "ds",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +172,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.12"
}
},
"nbformat": 4,
Expand Down