Beispiel #1
0
def sumOfEvenFibNumbers(max = 100):
  """Find the sum of even Fibonacci numbers below max"""
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  last_num = 1
  this_num = 1
  sum_of_fib_nums = 0

  while this_num <  max: 
    if this_num % 2 == 0:
      sum_of_fib_nums += this_num
    print '%d -- %d' % (this_num, sum_of_fib_nums)
    next_num = fibonacci.nextFib(last_num, this_num)
    last_num = this_num
    this_num = next_num
Beispiel #2
0
def getFirstFibNumberWithNDigits(n_digits):
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  itr = 2
  last_num = 1
  this_num = 1

  terminal = int(10**(n_digits-1))

  while this_num < terminal:
    itr += 1
    next_num = fibonacci.nextFib(last_num, this_num)
    last_num = this_num
    this_num = next_num

  print 'The %d Fibonacci number is the first term with %d digits is %d' % (itr, n_digits, this_num)