I've written a function that performs as a calculator. It works for the variables below.
However I want to scale it up to handle 15 different levels
values, and 15 different sales
and cost
values. The function would apply different sales and cost calculations per level as below. (In that each calculation applies to a particular level, the calculations could potentially be defined outside the function.)
I could write numerous if/elif statements for each of the 15 levels, but that doesn't seem very Pythonic. Is there a method for programmatically scaling such a function to take many more sales, levels and costs?
For clarity's sake, the output would be the same as below (depending on the values entered of course) but the function should just be able to handle many more values.
levels_list = [4, 5] # ultimately 15 values in this list
sale4 = 18280 # ultimately 15 of these values
sale5 = 19180
sale6 = 22170
cost1 = 224 # and 15 of these values
cost2 = 335
cost3 = 456
def sales(level, foo, bar):
for level in levels_list:
if level == 4:
x = cost1 + sale4 * foo
y = cost2 + sale4 * bar
z = x + y
elif level == 5:
x = cost2 + sale5 * foo
y = cost3 + sale5 * bar
z = x + y
return pd.DataFrame({'Total Cost':[z], 'x_Cost':[x], 'y_Cost':[y]})
sales(5, 10, 10)
Total Cost x_Cost y_Cost
0 384391 192135 192256