Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago