First off, sorry about the confusing title but its the only way i could think of describing it. A piece of coursework which i got handed recently asked a question that was to define a function with one argument(x), that returned another function with one parameter(y)which itself would return x*y. We were asked to write this out either using normal functions or lambda's which i opted for lamdas, writing this:
def create_multiplier (x):
return lambda y: y * x
input1 = int(raw_input("Please enter your initial number for our multiplier"))
multi = create_multiplier(input1)
input2 = int(raw_input("Please enter your second number for our multiplier"))
print input1, " times by ", input2, " = " ,multi(input2)
However i'm now curious how they expected us to achieve it with only functions,initially i thought that maybe you would pass your first number to x in the first function, then pass a number too our second function for y, and because we were returning the second function inside the first, we could use x like a nested variable. That got shot down quick
I understand if you are not willing to reply as this is coursework but this has just got me curious how you were meant to achieve it without presetting our x in a lambda, maybe I'm just looking at it weirdly and its blatantly obvious. Thank you for your replies