Skip to content
Open
Show file tree
Hide file tree
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
140 changes: 138 additions & 2 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,147 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5b26388b",
"metadata": {},
"outputs": [],
"source": [
"def initialize_inventory(products = [\"manzanas\", \"sandía\", \"banana\",\"fresas\",\"melón\"]):\n",
" inventory = {}\n",
" for product in products:\n",
" quantity = int(input(f\"Enter the quantity of {product}: \"))\n",
" inventory[product] = quantity\n",
" return inventory"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "9854d464",
"metadata": {},
"outputs": [],
"source": [
"def get_customer_orders():\n",
" customer_orders = set()\n",
" add_more = \"yes\"\n",
" while add_more == \"yes\":\n",
" product = input(\"Enter a product name: \")\n",
" customer_orders.add(product)\n",
" add_more = input(\"Do you want to add another product? (yes/no): \")\n",
" return customer_orders"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "21ef085f",
"metadata": {},
"outputs": [],
"source": [
"def update_inventory(customer_orders, inventory):\n",
" for product in customer_orders:\n",
" if product in inventory:\n",
" inventory[product] -= 1\n",
" return inventory"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "a965e021",
"metadata": {},
"outputs": [],
"source": [
"def calculate_order_statistics(customer_orders, products):\n",
" total_ordered = len(customer_orders)\n",
" percentage = (total_ordered / len(products)) * 100\n",
" return total_ordered, percentage"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "82cd30da",
"metadata": {},
"outputs": [],
"source": [
"def print_order_statistics(order_statistics):\n",
" total, percentage = order_statistics\n",
" print(\"\\nOrder Statistics:\")\n",
" print(f\"Total Products Ordered: {total}\")\n",
" print(f\"Percentage of Products Ordered: {percentage:.2f}%\")"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "bf4ae269",
"metadata": {},
"outputs": [],
"source": [
"def print_updated_inventory(inventory):\n",
" print(\"\\nUpdated Inventory:\")\n",
" for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "9f3461fe",
"metadata": {},
"outputs": [],
"source": [
"def initialize_inventory(products = [\"manzanas\", \"sandía\", \"banana\",\"fresas\",\"melón\"]):\n",
" inventory = {}\n",
" for product in products:\n",
" quantity = int(input(f\"Enter the quantity of {product}: \"))\n",
" inventory[product] = quantity\n",
" return inventory\n",
"\n",
"def get_customer_orders():\n",
" customer_orders = set()\n",
" add_more = \"yes\"\n",
" while add_more == \"yes\":\n",
" product = input(\"Enter a product name: \")\n",
" customer_orders.add(product)\n",
" add_more = input(\"Do you want to add another product? (yes/no): \")\n",
" return customer_orders\n",
"\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",
"\n",
"def calculate_order_statistics(customer_orders, products):\n",
" total_ordered = len(customer_orders)\n",
" percentage = (total_ordered / len(products)) * 100\n",
" return total_ordered, percentage\n",
"\n",
"def print_order_statistics(order_statistics):\n",
" total, percentage = order_statistics\n",
" print(\"\\nOrder Statistics:\")\n",
" print(f\"Total Products Ordered: {total}\")\n",
" print(f\"Percentage of Products Ordered: {percentage:.2f}%\")\n",
"\n",
"def print_updated_inventory(inventory):\n",
" print(\"\\nUpdated Inventory:\")\n",
" for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")\n",
"\n",
"# --- Programa principal ---\n",
"products = [\"manzanas\", \"sandía\", \"banana\",\"fresas\",\"melón\"]\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": ".venv-1 (3.15.0)",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +197,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.15.0a7"
}
},
"nbformat": 4,
Expand Down
48 changes: 48 additions & 0 deletions lab_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
def initialize_inventory(products):
products = ["manzanas", "sandía", "banana", "fresas", "melón"]
inventory = {}
for product in products:
quantity = int(input(f"Enter the quantity of {product}: "))
inventory[product] = quantity
return inventory

def get_customer_orders():
customer_orders = set()
add_more = "yes"
while add_more == "yes":
product = input("Enter a product name: ")
customer_orders.add(product)
add_more = input("Do you want to add another product? (yes/no): ")
return customer_orders

def update_inventory(customer_orders, inventory):
for product in customer_orders:
if product in inventory:
inventory[product] -= 1
return inventory

def calculate_order_statistics(customer_orders, products):
total_ordered = len(customer_orders)
percentage = (total_ordered / len(products)) * 100
return total_ordered, percentage

def print_order_statistics(order_statistics):
total, percentage = order_statistics
print("\nOrder Statistics:")
print(f"Total Products Ordered: {total}")
print(f"Percentage of Products Ordered: {percentage:.2f}%")

def print_updated_inventory(inventory):
print("\nUpdated Inventory:")
for product, quantity in inventory.items():
print(f"{product}: {quantity}")

# --- Programa principal ---
products = ["manzanas", "sandía", "banana", "fresas", "melón"]

inventory = initialize_inventory(products)
customer_orders = get_customer_orders()
inventory = update_inventory(customer_orders, inventory)
order_statistics = calculate_order_statistics(customer_orders, products)
print_order_statistics(order_statistics)
print_updated_inventory(inventory)
1 change: 1 addition & 0 deletions python lab_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python lab_functions.py