Question: This program will prompt the user for a positive integer n and then display the nth Fibonacci number. TypeError: can only concatenate str (not int)

This program will prompt the user for a positive integer n and then display the nth Fibonacci number.

TypeError: can only concatenate str (not "int") to str

Can someone explain why ?

def get_num():

#prompt user for a number

n = input('Which Fibonacci number would you like to see? ')

#Negetive numbers are not accepted.

assert n.isnumeric(), "Number has to be positive! "

return n

def fib_bottom_up(n):

if n == 1 or n == 2:

return 1

bottom_up = [None] * (n + 1)

bottom_up[1] = 1

bottom_up[2] = 1

for i in range(3,n+1):

bottom_up[i] = bottom_up[i-1]+bottom_up[i-2]

return bottom_up[n]

x = get_num()

print(fib_bottom_up(x))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!