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
85 changes: 83 additions & 2 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,92 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f1e935bb",
"metadata": {},
"outputs": [],
"source": [
"def initialize_inventory(products):\n",
" products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
" inventory = {}\n",
"\n",
" for product in products:\n",
" quantity = int(input(f\"Please enter the quantity of the {product} available\"))\n",
" inventory[product]= quantity #dict_name[key] = value"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9913a5cc",
"metadata": {},
"outputs": [],
"source": [
"customer_orders = set()\n",
"def get_customer_orders():\n",
" another_order = \"YES\" #set a true value for while loop, so it automatically ends when this is false \n",
" while another_order == \"YES\":\n",
" order_items = input(\"Please enter the name of the product you want to order: \")\n",
" customer_orders.add(order_items) #here the product ordered is added to the set\n",
" another_order = input(\"Do you want to order another product? Please type 'YES' or 'NO': \")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0f049094",
"metadata": {},
"outputs": [],
"source": [
"def update_inventory(customer_orders, inventory):\n",
" for product, quantity in inventory.items(): #remember to use the key,value format when updating a dictionary!!!\n",
" if product in customer_orders:\n",
" inventory[product] = quantity -1 #dict_name[key] = value - 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "acc30174",
"metadata": {},
"outputs": [],
"source": [
"def calculate_order_statistics(customer_orders, products):\n",
" return customer_orders\n",
" available_products = products.count()\n",
" products_ordered = len(customer_orders)\n",
" percentage_of_unique_products_ordered = products_ordered / available_products"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1b301175",
"metadata": {},
"outputs": [],
"source": [
"def print_order_statistics(order_statistics):\n",
" print (order_statistics)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "c105bcf8",
"metadata": {},
"outputs": [],
"source": [
"def print_updated_inventory(inventory):\n",
" print (inventory)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +142,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down