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
173 changes: 171 additions & 2 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,180 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "e2086d88",
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\",\"mug\",\"hat\",\"book\",\"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "388f54be",
"metadata": {},
"outputs": [],
"source": [
"#1.\n",
"inventory = {}\n",
"def initialize_inventory(products):\n",
"\n",
" for product in products:\n",
" quantity = int(input(f\"Enter the quantity for {product}:\"))\n",
" \n",
" inventory [product] = quantity #assign the product name as the key and the quantity as the value\n",
"\n",
" return inventory #return full dictionary\n",
" \n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "2ad51c49",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 50, 'mug': 100, 'hat': 20, 'book': 30, 'keychain': 100}\n"
]
}
],
"source": [
"print(initialize_inventory(products))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "a492dc00",
"metadata": {},
"outputs": [],
"source": [
"#2\n",
"\n",
"customer_orders = set()\n",
"def get_customer_orders():\n",
" continuing_order =\"yes\"\n",
" while continuing_order==\"yes\":\n",
" product = (input(f\"Enter a product name:\"))\n",
" customer_orders.add(product)\n",
" continuing_order = input (f\"Add another?( yes/no):\")\n",
" return customer_orders"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "d139b329",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'mug', 'book', 'hat'}\n"
]
}
],
"source": [
"print(get_customer_orders())"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "0aa784b2",
"metadata": {},
"outputs": [],
"source": [
"#3\n",
"def update_inventory (customer_orders, inventory):\n",
" for product in customer_orders:\n",
" if product in inventory: \n",
" inventory[product] -= 1\n",
" return inventory \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "199f7d79",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 50, 'mug': 99, 'hat': 19, 'book': 29, 'keychain': 100}\n"
]
}
],
"source": [
"print(update_inventory(customer_orders,inventory))"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "41a68508",
"metadata": {},
"outputs": [],
"source": [
"#4 \n",
"def calculate_order_statistics(customer_orders,products): \n",
" total_products_ordered = len (customer_orders)\n",
" percentage_ordered = (len(customer_orders)/len(products))*100\n",
" return total_products_ordered, percentage_ordered"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "ad5033ee",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Products ordered: 3\n",
"Percentage of Catalog: 100.0%\n"
]
}
],
"source": [
"#5 \n",
"def print_order_statistics (order_statistics):\n",
" total,percent = calculate_order_statistics(customer_orders,products)\n",
"print(f\"Total Products ordered: {total}\")\n",
"print(f\"Percentage of Catalog: {percent}%\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f0dcb295",
"metadata": {},
"outputs": [],
"source": [
"#6 \n",
"def "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +230,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.2"
}
},
"nbformat": 4,
Expand Down