Fisher: Difference between revisions

1,894 bytes added ,  8 November
Making a Recipe table with cost and possible profit
mNo edit summary
(Making a Recipe table with cost and possible profit)
Line 1,652:
|
|}
<syntaxhighlight lang="python">
# List of recipes with their ingredients, costs, sold price, and profit
recipes = [
{
"name": "Bacon Sandwich",
"ingredients": [("Bread", 200), ("Bacon", 200)],
"sold_price": 560,
"profit": 160
},
{
"name": "Appetizing Bacon Sandwich",
"ingredients": [("Bread", 200), ("Appetizing Bacon", 320)],
"sold_price": 776,
"profit": 256
},
{
"name": "Basic Omelette",
"ingredients": [("Egg", 240)],
"sold_price": 336,
"profit": 96
},
{
"name": "Basic Sausage and Mash",
"ingredients": [("Raw Sausage", 260), ("Potato", 700)],
"sold_price": 850,
"profit": -110
},
{
"name": "Basic Vegetable Stew",
"ingredients": [("Mixed Vegetables", 280)],
"sold_price": 492,
"profit": 212
}
]
 
# Function to calculate the total cost of ingredients for each recipe
def calculate_total_cost(ingredients):
return sum(cost for ingredient, cost in ingredients)
 
# Function to generate and print a Wiki-style markdown table
def generate_wiki_table(recipes):
# Table header
table_header = "| Recipe | Total Ingredient Cost | Sold Price | Profit | Expected Profit |"
separator = "|--------|-----------------------|------------|--------|-----------------|"
# Print the header and separator
print(table_header)
print(separator)
# Iterate over each recipe and print the data in a markdown table format
for recipe in recipes:
total_cost = calculate_total_cost(recipe["ingredients"])
expected_profit = recipe["sold_price"] - total_cost
print(f"| {recipe['name']} | {total_cost} | {recipe['sold_price']} | {recipe['profit']} | {expected_profit} |")
 
# Display the Wiki-style table
generate_wiki_table(recipes)
</syntaxhighlight>
 
==Update history==
Anonymous user