Skip to content

lab-python-functions #442

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
121 changes: 118 additions & 3 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,128 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "5c622ae4-0e53-4ec8-bbfd-5524499bc93f",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Please enter stock for article t-shirt 1\n",
"Please enter stock for article mug 2\n",
"Please enter stock for article hat 3\n",
"Please enter stock for article book 4\n",
"Please enter stock for article keychain 5\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Would you like to order? Please enter 1 for yes and 0 for no. 1\n",
"Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain 1\n",
"Would you like to order something else? Please enter 1 for yes and 0 for no. 1\n",
"Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain 2\n",
"Would you like to order something else? Please enter 1 for yes and 0 for no. 0\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Thank you for your order.\n",
"{'hat', 'mug'}\n",
"Order Statistics:\n",
" Total Products Ordered: 2\n",
" Percentage of Products Ordered: 40.0 %\n",
"The stock for t-shirt is 1\n",
"The stock for mug is 1\n",
"The stock for hat is 2\n",
"The stock for book is 4\n",
"The stock for keychain is 5\n"
]
}
],
"source": [
"def initialize_inventory(products):\n",
" \"\"\"Initializing a dictionary for inventory input\"\"\"\n",
" inventory = {}\n",
" for product in products:\n",
" stock = int(input(f\"Please enter stock for article {product}\"))\n",
" inventory[product] = stock\n",
" return inventory\n",
"\n",
"def get_customer_orders():\n",
" \"\"\"Creates Set for customer order input\"\"\"\n",
" customer_orders = set()\n",
" question = int(input(\"Would you like to order? Please enter 1 for yes and 0 for no.\"))\n",
" while question == 1:\n",
" customer_orders.add(products[int(input(\"Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain\"))])\n",
" question = int(input(\"Would you like to order something else? Please enter 1 for yes and 0 for no.\"))\n",
" print(\"Thank you for your order.\")\n",
" return customer_orders\n",
"\n",
"def update_inventory(customer_orders, inventory):\n",
" for product in customer_orders:\n",
" inventory[product] -= 1\n",
" return inventory\n",
"\n",
"def calculate_order_statistics(customer_orders, products):\n",
" total_products_ordered = len(customer_orders)\n",
" percentage_ordered = (len(customer_orders)/len(inventory.values()))*100\n",
" return(total_products_ordered, percentage_ordered)\n",
"\n",
"def print_order_statistics(order_statistics):\n",
" print(f\"\"\"Order Statistics:\n",
" Total Products Ordered: {order_statistics[0]}\n",
" Percentage of Products Ordered: {order_statistics[1]} %\"\"\")\n",
"\n",
"def print_updated_inventory(inventory):\n",
" for product in products:\n",
" print(\"The stock for\", product, \"is\", inventory[product])\n",
"\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = initialize_inventory(products)\n",
"print(inventory)\n",
"\n",
"customer_orders = get_customer_orders()\n",
"print(customer_orders)\n",
"\n",
"order_statistics = calculate_order_statistics(customer_orders, products)\n",
"\n",
"print_order_statistics(order_statistics)\n",
"\n",
"inventory = update_inventory(customer_orders, inventory)\n",
"\n",
"print_updated_inventory(inventory)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1f1b34a1-34ff-4fdd-8fb7-5f51bf3039c1",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "python3"
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -61,7 +176,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down