问题:如何根据stat_frac_sales()
的自变量stat_requested
调用def stat_frac_sales(company, input1, input2, stat_requested):
stat_data = # call a function here based on the value of stat_requested
sales = import_sales(company) # Sales function that will not vary
ratio= stat_data/sales
return ratio
中的其他函数?
我要计算一个财务比率,该比率将具有不同的分子(收益,毛利润等),但分母始终相同(销售额)。看起来像这样:
stat_requested = 'FCT'
例如,如果为FCT()
,则应调用函数FCT
。
例如EBIT
和def FCF(company, input1)
...some code
return FCF
def EBIT(company, input2)
...some different code
return EBIT
函数看起来像:
FCF
因此,如果用户调用stat_data='FCF'
(def stat_frac_sales(company, input1, input2, stat_requested):
stat_data = FCF(company, input1) # <-- like so but unclear as to how to make this dynamic, where the function called here changes based on stat_requested
sales = import_sales(company) # Sales function that will not vary*
ratio= stat_data/sales
return ratio
),则它看起来像这样:
class Program
{
static void Main(string[] args)
{
using (RecipesEntities context = new RecipesEntities())
{
//context.Categories.Add(new Category { Name = "Breakfast" });
//context.Categories.Add(new Category { Name = "Lunch" });
//new receipe and assign it to these two new categories
// 1. Using Id properties
//Category category = context.Categories.FirstOrDefault(c => c.Name == "Breakfast");
//context.Recipes.Add(new Recipe { Name = "Cereal", CategoryId = category.Id });
// 2. Recipe.Category navigation property
Category category = context.Categories.FirstOrDefault(c => c.Name == "Lunch");
context.Recipes.Add(new Recipe { Name = "Pizza", Category = category });
context.SaveChanges();
}
}
}
希望这很清楚。任何有关如何执行此操作的想法将不胜感激。