Consider the following piece of code:
def integ(fncts, propagate, stpSz):
conditions = propagate.copy()
iterator = 0
for i in fncts:
conditions[iterator] = conditions[iterator] + stpSz * i(0)
iterator+=1
return conditions
Where fncts is an array of functions, like this:
f1 = lambda x: x
f2 = lambda x: 2*x
fncts = (f1, f2)
Problem is, the code above works for length(fncts)>1. However, if there is only one function, it fails. How I can make sure the code can be executed if the user inputs only one function?
inteqlike thisinteg((f1), propagate, stpSz)instead of like thisinteg((f1,), propagate, stpSz). Note the comma afterf1. That makes it a tuple rather than just parenthesis.