+ 1
Why does it say 'int' object no callable?
I was doing a little thing where I created a random function and wanted to make a function that generates a list where the function of each number, from 1 to the end assigned, is included. But it says error: 'int' object not callable. Also, could you give me recomendations on how to improve this? import math def factorial_factorial(x): x=math.factorial(math.factorial(x)) return x def func_list(func,x): i=1 for i in range(x+1): yield func(i) i+=1 print(list(func_list(factorial_factorial(3),3)))
3 Answers
+ 2
First parameter of func_list is a function, so you have to pass the function name.
print(list(func_list(factorial_factorial,3)))
+ 2
Your 'func_list' function accepts a function 'func' and a number 'x' as arguments. You are currently calling it by passing 'factorial_factorial(3)' as your 'func' parameter, but notice that 'factorial_factorial(3)' evaluates to 3!! = 720. Thus, you are passing a number instead of a function.
The correct function call is:
func_list(factorial_factorial, 3)
0
thanks a lot, it worked