recursion problem
why does y = fib(1000) would cause an error on my end?
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
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
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
I already did that, it doesn't cause any errors but it doesn't seem to reflect in the console
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
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
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