Skip to content
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

week1 lab2.2 done #320

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
190 changes: 189 additions & 1 deletion lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,194 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 166,
"id": "0053f469-a9d2-4d3f-be4b-4652ab1b9096",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Choose the quantity of each product\n",
"Choose the quantity of t-shirt\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the quantity : 18\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Choose the quantity of mug\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the quantity : 22\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Choose the quantity of hat\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the quantity : 12\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Choose the quantity of book\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the quantity : 10\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Choose the quantity of keychain\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the quantity : 26\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"You have to choose 3 products for your order\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"choose product 1 : hat\n",
"choose a quantity : 5\n",
"choose product 2 : book\n",
"choose a quantity : 8\n",
"choose product 3 : mug\n",
"choose a quantity : 15\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Order_statistics :\n",
"('The number of product ordered is 3', 'The percentage of all product ordered is 60')\n",
"\n",
"Inventory updated\n",
"{'t-shirt': 18, 'mug': 7, 'hat': 7, 'book': 2, 'keychain': 26}\n"
]
}
],
"source": [
"\n",
"def initialize_inventory(products):\n",
" print (\"Choose the quantity of each product\")\n",
" inventory = {}\n",
"\n",
" for i in products:\n",
" print(f\"Choose the quantity of {i}\")\n",
" inventory[i] = int(input(\"Enter the quantity :\"))\n",
"\n",
" return inventory\n",
"\n",
"inventory = initialize_inventory(products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"])\n",
"\n",
"def get_customer_orders():\n",
" print (\"You have to choose 3 products for your order\")\n",
" customer_orders = {}\n",
"\n",
" for i in range (1, 4):\n",
" prod = input(f\"choose product {i} : \") \n",
" if prod in products:\n",
" qté = int(input(\"choose a quantity : \"))\n",
" customer_orders[prod] = qté\n",
" else :\n",
" while prod not in products :\n",
" print(\"the product is not in the list\")\n",
" prod = input(f\"choose product {i} : \")\n",
" qté = int(input(\"choose a quantity : \"))\n",
" customer_orders[prod] = qté\n",
" \n",
" \n",
" return customer_orders\n",
" \n",
"customer_orders = get_customer_orders()\n",
"\n",
"def update_inventory(customer_orders, inventory):\n",
" for prod, qté in customer_orders.items():\n",
" if prod in inventory:\n",
" if inventory[prod] >= qté:\n",
" inventory[prod] -= qté\n",
" else:\n",
" print(f\"Not enough stock for {prod}.\")\n",
" return inventory\n",
"\n",
"inventory = update_inventory(customer_orders, inventory)\n",
"\n",
"\n",
"def calculate_order_statistics(customer_orders, products):\n",
"\n",
" number_in_co = len(customer_orders)\n",
" percentage_product = int((number_in_co / len(products)) * 100)\n",
"\n",
" return (f\"The number of product ordered is {number_in_co}\"), (f\"The percentage of all product ordered is {percentage_product}\")\n",
"\n",
"order_statistics = calculate_order_statistics(customer_orders, products)\n",
"\n",
"def print_order_statistics(order_statistics):\n",
" print()\n",
" print (\"Order_statistics :\")\n",
" print (order_statistics)\n",
" print ()\n",
"\n",
"print_order_statistics(order_statistics)\n",
"\n",
"def print_update_inventory(inventory):\n",
" print (\"Inventory updated\")\n",
" print (inventory)\n",
"\n",
"print_update_inventory(inventory)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "17cc70c7-75fe-477d-ab79-1278539862d3",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -61,7 +249,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down