0

I'm trying to learn Python with the help of Project Euler.

I'm having a bit of trouble with this piece of code (For Problem 2) and what exactly a 'Non type' is. I was wondering if anyone could help point me in the right direction!

from math import sqrt
x= 0 

def f(n):
    return ((1+sqrt(5))**n-(1-sqrt(5))**n)/(2**n*sqrt(5))

def SubFib(startNumber, endNumber):
    n = 0
    cur = f(n)
        while cur <= endNumber:
        if startNumber <= cur:
        print (cur)
        n += 1
        cur = f(n)


        for i in range(SubFib(1,4000000)):
        if i % 2 ==0:
        x = i+ x 

Thank-You in Advance!

2
  • 1
    Wekcome to Stack overflow! Please check the indentation of your code - as it stands it doesn't look like it would work... You should also post the exact error you see (usually with traceback) and what you expected (don't assume that people will definitely work it out - they might in this case, but not generally). Make sure you've read how to ask. Good luck! Commented Jun 27, 2015 at 23:13
  • 1
    Once you've fixed the NoneType next issue is RuntimeError: maximum recursion depth exceeded as a result of SubFib(1,4000000). Does it always need to be this high a value? Commented Jun 27, 2015 at 23:15

1 Answer 1

2

A NoneType error is what happens when something has the value None and you try to do something with it. In this case, your SubFib function never returns anything, so when you call it and pass its result to range(), it tries to run range(None).

Perhaps you want SubFib to have a return n at the end?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.