sds2019 icon indicating copy to clipboard operation
sds2019 copied to clipboard

problem 0.3.4

Open markusbruun opened this issue 5 years ago • 3 comments

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?

markusbruun avatar Aug 07 '19 12:08 markusbruun

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 :)

sebastianbaltser avatar Aug 07 '19 12:08 sebastianbaltser

Thanks!

markusbruun avatar Aug 08 '19 09:08 markusbruun

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 (?)

akaisin avatar Aug 11 '19 17:08 akaisin