# ==============================================================================
"""FIBO : compute the n first terms of the Fibonacci sequence"""
# ==============================================================================
__author__  = "Christophe Schlick modified by Philippe Blasi"
__version__ = "2.0" # use recursive implementation of the Fibonacci terms
__date__    = "2022-11-12"
__usage__   = """
User input: <n> (where n:int >= 0)
App output: sequence of the n first Fibonacci terms"""
# ==============================================================================
from ezCLI import *
# ------------------------------------------------------------------------------
def fibo(n:int) -> int:
  """return the nth term of the Fibonacci sequence (recursive version)"""
  if n < 2: return n
  else: return fibo(n-2) + fibo(n-1)
  # Alternative implementation using conditional evaluation
  # return n if (n < 2) else fibo(n-2) + fibo(n-1)
# ------------------------------------------------------------------------------
def fibos(n:int) -> str:
  """return a string containing the 'n' first terms of the Fibonacci sequence"""
  lines = ''
  for p in range(n+1):
    lines += f"fibo({p}) = {fibo(p)}\n"
  return lines.strip()
  # Alternative implementation using list comprehension
  #return '\n'.join(f"fibo({p}) = {fibo(p)}" for p in range(n+1))
# ------------------------------------------------------------------------------
def parser(command:str) -> str:
  """parse 'command' as integer 'n' before calling 'fibos(n)'"""
  n = parse(command)
  assert type(n) is int and n >= 0, "<n> must be a positive integer"
  return fibos(n)
# ==============================================================================
if __name__ == "__main__":
  userloop(parser, "Enter value for <n>")
# ==============================================================================
