sds2019
sds2019 copied to clipboard
problem 0.3.4
Hi
I am working on the last problem (0.3.4) and find it a little difficult
First of all, how can we call logexp(1,1000), when it has to be stored as a variable, and not a function?
Secondly, if the inner function has to return func(e, k), my guess has been that the value should equal func (e, k), but it does not work out for me. Maybe I just do not understand the problem?
A variable can refer to a function and thus behave in the same way as the function. Check out this example with the len
function:
>>> len([1,2,3,4])
4
>>> len_function_variable = len
>>> len_function_variable([1,2,3,4])
4
Also see this example to understand how the whole "functions returning functions"-thing works:
def some_function():
print("some_function now runs") #The functions print their names so we can see when they run
def outer_function(func):
print("outer_function now runs")
def inner_function():
print("inner_function now runs")
func()
return inner_function
#We 'decorate' some_function and variable now holds the returned value of outer_function that is inner_function
variable = outer_function(some_function) #The outer_function runs here
Result:
>>> print("variable now runs")
>>> variable() #Run variable which refers to inner_function
outer_function now runs
variable now runs
inner_function now runs
some_function now runs
Hope this makes sense :)
Thanks!
I've been messing with this exercise for the past 45min or so and am thinking that the return for the inner function is simply func(e,k) ?? this would allow for the natural_logarithm function to use the e and k.
somehow the checking code isn't working properly because whatever I write the assert functions don't pull up red flags (?)