+ 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?

23rd Oct 2016, 2:37 AM
toygrill11
3 Answers
+ 6
the second function definition is bit incorrect you should write it like this def test(square, x): return square(x)
25th Oct 2016, 6:03 AM
Sahil Kumar
Sahil Kumar - avatar
+ 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.
24th Oct 2016, 6:06 PM
Badal Saibo
Badal Saibo - avatar
0
re-write test to be this: def test(func, x): print(func(x)) right now you dont ever call the function square.
23rd Oct 2016, 2:52 AM
Luke Armstrong