Skip to content

medilin pull request #464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
234 changes: 232 additions & 2 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,241 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "7ecad8b9",
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\",\"mug\",\"hat\",\"book\",\"keychain\"] "
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "c74808c3",
"metadata": {},
"outputs": [],
"source": [
"def initialize_inventory(products):\n",
" inventory = {}\n",
" for product in products:\n",
" quantity = int(input(f\"how many {product} available?\"))\n",
" inventory[product] = quantity\n",
" return inventory"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4fa39dd7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 3, 'mug': 5, 'hat': 32, 'book': 45, 'keychain': 2}\n"
]
}
],
"source": [
"inventory = initialize_inventory(products)\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "df838750",
"metadata": {},
"outputs": [],
"source": [
"def get_customer_orders():\n",
" customer_orders = set()\n",
" continue_to_buy = \"yes\"\n",
" while continue_to_buy == \"yes\":\n",
" customer_orders.add(input(f\"select product out of 't-shirt','mug','hat','book','keychain'\"))\n",
" continue_to_buy = input(\"Continue to buy? (yes/no)\")\n",
" return customer_orders"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "3654f87b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'hat', 'book'}\n"
]
}
],
"source": [
"customer_orders = get_customer_orders()\n",
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "1e430668",
"metadata": {},
"outputs": [],
"source": [
"def update_inventory(customer_orders, inventory):\n",
" for product in customer_orders:\n",
" inventory[product] = inventory[product] - 1"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "950f0d35",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 3, 'mug': 5, 'hat': 31, 'book': 44, 'keychain': 2}\n"
]
}
],
"source": [
"update_inventory(customer_orders, inventory)\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "a86c7593",
"metadata": {},
"outputs": [],
"source": [
"def calculate_order_statistics(customer_orders, products):\n",
" return (len(customer_orders), (len(customer_orders)/len(products))*100)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "b595fa90",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"total products ordered: 2, percentage ordered: 40.0\n"
]
}
],
"source": [
"(total_products_ordered, percentage_ordered) = calculate_order_statistics(customer_orders, products)\n",
"print(f\"total products ordered: {total_products_ordered}, percentage ordered: {percentage_ordered}\")"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "0385d7e9",
"metadata": {},
"outputs": [],
"source": [
"def print_order_statistics(order_statistics):\n",
" print(f\"total products ordered: {order_statistics[0]}\")\n",
" print(f\"percentage ordered: {order_statistics[1]}%\")"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "116913c8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"total products ordered: 2, percentage ordered: 40.0%\n"
]
}
],
"source": [
"order_statistics = calculate_order_statistics(customer_orders, products)\n",
"print_order_statistics(order_statistics)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "dd140faf",
"metadata": {},
"outputs": [],
"source": [
"def print_updated_inventory(inventory):\n",
" print(\"Updated Inventory :\")\n",
" for product in inventory.keys():\n",
" print(f\" {product}: {inventory[product]}\")"
]
},
{
"cell_type": "markdown",
"id": "1c849eb0",
"metadata": {},
"source": [
"call the functions in approppriate sequence"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "1d8e82d6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"total products ordered: 3\n",
"percentage ordered: 60.0%\n",
"Updated Inventory :\n",
" t-shirt: 23\n",
" mug: 33\n",
" hat: 53\n",
" book: 1\n",
" keychain: 45\n"
]
}
],
"source": [
"inventory = initialize_inventory(products)\n",
"customer_orders = get_customer_orders()\n",
"update_inventory(customer_orders, inventory)\n",
"order_statistics = calculate_order_statistics(customer_orders, products)\n",
"print_order_statistics(order_statistics)\n",
"print_updated_inventory(inventory)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4181c08d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +291,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.11.13"
}
},
"nbformat": 4,
Expand Down