Last answered:

27 Oct 2023

Posted on:

23 Oct 2023

0

recursion problem

why does y = fib(1000) would cause an error on my end?

9 answers ( 0 marked as helpful)
Instructor
Posted on:

23 Oct 2023

0

Hey Leila,


Thank you for reaching out!


Could you please provide a screenshot of your code and the error you are getting?


Note that solving the Fibonacci numbers problem recursively is very inefficient. An iterative solution would solve the task much faster, especially for larger numbers.


Kind regards,

365 Hristina

Posted on:

25 Oct 2023

0

Instructor
Posted on:

26 Oct 2023

0

Hey Leila,


Thank you for your response.


The code looks fine to me. Could you please take a screenshot of the error you get when you run it?


Kind regards,

365 Hristina

Posted on:

26 Oct 2023

0

Instructor
Posted on:

26 Oct 2023

0

Hey again Leila,


Thank you for the response.


As the error reads, you haven't defined a funtion called fib but you attempt to use it in line 138. Change that line of code to:

y = fib_2(1000)

and your code should run smoothly.


Kind regards,

365 Hristina

 

Posted on:

26 Oct 2023

0

I already did that, it doesn't cause any errors but it doesn't seem to reflect in the console

Instructor
Posted on:

26 Oct 2023

0

Hey,


I've implemented the code from your screenshot (I've used smaller numbers - 5 and 10) and got the corresponsding output in the console. You can also see the variables x and y appear in the Variable Explorer tab (see screnshot attached).



Could you please clarify what you mean by "it doesn't reflect in the console"?


Kind regards,

365 Hristina

Posted on:

27 Oct 2023

0

like the solution you gave me doesn't cause any errors, but if I run it, it doesn't seem to reflect in the terminal 

Instructor
Posted on:

27 Oct 2023

0

Hey Leila,


If you run the code from my previous response, you should have the result printed out in the terminal. Unfortunately, I'm not sure why the output doesn't appear for you.


Maybe you could share a screenshot of your code and the terminal after you've run the code.


Best,

365 Hristina

Submit an answer