Having issue in the follwing code, it looks like I am facing issue with either list or int operations, so where and how should I do the changes to correct this code:
cube = lambda x:x**3 def fibonacci(n): fb=[0,1] for i in range(2,n-1): fb.append([fibonacci(i-1)+fibonacci(i-2)]) return fb if __name__ == '__main__': n = int(input()) print(list(map(cube, fibonacci(n)))) Error: --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-9-761cca8f2b48> in <module> 7 if __name__ == '__main__': 8 n = int(input()) ----> 9 print(list(map(cube, fibonacci(n)))) <ipython-input-9-761cca8f2b48> in <lambda>(x) ----> 1 cube = lambda x:x**3 2 def fibonacci(n): 3 fb=[0,1] 4 for i in range(2,n-1): 5 fb.append([fibonacci(i-1)+fibonacci(i-2)]) TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
https://stackoverflow.com/questions/67239487/cube-for-fibonacci April 24, 2021 at 01:05PM
没有评论:
发表评论