I've been trying to write a code for Fibonacci using memorization on Python.
Here's my code
def fib(n, memo):
if memo[n] is not None:
return memo[n]
if n == 1 or n == 2:
result = 1
else:
result = fib_2(n-1, memo) + fib_2(n-2, memo)
memo[n] = result
return result
def fib_memo(n):
memo = [None] * (n + 1)
return fib(n, memo)
t = input("number ")
print(fib_memo(t))
It returns:-
TypeError: must be str, not int" on line 17- memo = [None] * (n + 1)
I can't seem to understand the issue here.
t = int(input("number"))orprint(fib_memo(int(t))). Because, keyboard input usinginput()are by default string.t = int(input("..."))