[Code-challenge] Fibonacci finder with Python

Hi all, really sorry if this has already been addressed in another thread, I’ve been searching around and can find similar topics but there isn’t anything that specifically addresses my issue. Feel free to point me to it if there is!

I’ve been attempting the beta code-challenge Fibonacci finder in Python (https://www.codecademy.com/code-challenges/code-challenge-fibonacci-finder-python). I feel like the script I’ve made meets all the requirements of the challenge, and I’ve also tried it out in the interview prep section on this exact topic (https://www.codecademy.com/paths/pass-the-technical-interview-with-python/tracks/interview-prep-and-practice/modules/python-interview-problems/articles/introduction-to-dynamic-programming-in-python) and got a pass.

When I click ‘Test Code’ in the code-challenge page however my script only passes 1/5 tests (it doesn’t mention what it’s failing which is very frustrating). There is no guidance on what the ‘correct’ script looks like either. I’m very much in the dark on what’s wrong with my code, so I would appreciate any help with identifying the issues so I can pass this code-challenge - thanks in advance! Code is below

memo = {}

def fib_finder(n):
  if n < 0:
    raise TypeError('function can not take negative numbers')
  elif not type(n) == int:
    raise TypeError('function can only take integers')
  elif n == 1 or n == 0:
    return n
  elif n in memo:
    return memo[n]
    result = fib_finder(n - 1) + fib_finder(n - 2)
    memo[n] = result
    return result


I think the bit you want to look at is this line specifically in the description of the tests:

fib_finder(1) and fib_finder(2) , which return 0 and 1 , respectively. fib_finder(6) should return 5

That might be different to what you expected. Compare your code to those expected answers and see if you can determine what may be different about the tests.

1 Like

Ah thank you so much! Classic case of not reading the full question on my part. I didn’t realise it wanted the series to start at Fib(1) rather than Fib(0) (as I had it originally). I’ve edited it to start at Fib(1) now and it passes all the tests, thanks for your help!

1 Like

I think it’s normally used the way you first expected but occasionally the definition wobbles a little.

1 Like