+ 1
what is going on why is it not squaring def square(x): return x*x def test(square, x): print(x) test (square, 12)
I believe it is because the print being in the test function but I'm not trying to get a simple squaring function I'm trying to use a function in a function any help?
3 Antworten
+ 6
the second function definition is bit incorrect
you should write it like this
def test(square, x):
return square(x)
+ 4
In the second def function you're not determining the return value to run the previous def function.
So the code becomes ,
def square(x):
return x*x
def test(square,x):
return square(x)
print test(square,12)
Now when the print statement is executed, its gonna pass it to the second def function which is gonna execute the 1st def function and the result will successfully be printed.
0
re-write test to be this:
def test(func, x):
print(func(x))
right now you dont ever call the function square.