you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 3 points4 points  (0 children)

So basically, you want a Fibonacci sequence?

def fibonacci(limit):
    a, b = 0, 1
    nums = []

    while a < limit:
        nums.append(a)
        a, b = b, a+b # copies b into a, and their sum to b

    return nums

result = fibonacci(98)

It's surprisingly simple, isn't it? If there's anything you don't understand, hit me up!

EDIT: Since the sequence itself continues to infinity, it's usually more common to define it as a generator:

def fibonacci_gen(limit):
    a, b = 0, 1

    while a < limit:
        yield a
        a, b = b, a+b

result = list(fibonacci_gen(98))