# ==============================================================================
"""PASCAL : create Pascal's triangle (triangle of binomial terms)"""
# ==============================================================================
__author__  = "Philippe Blasi"
__version__ = "2.0" # Compute the triangle with computing binomial number
__date__    = "2026-03-06"
__usage__   = """
User input : <n> (where n:int > 0)
App output: Grid containing Pascal's triangle up to rank n"""
# ==============================================================================
from ezCLI import *
# ------------------------------------------------------------------------------
def pascal(n:int) -> str:
  """return a grid containing Pascal's triangle up to rank n"""
  table = [[1 for col in range(0,row+1)] for row in range(0, n+1)]; #inspect()

  # boucle for sur les lignes
  for row in range(2, n+1):
    # boucle sur les colonne
    for col in range(1,row):
      # chaque case en row,col est la somme des deux deux cases de la ligne au dessus
      # en row-1,col etrow-1,col-1
      table[row][col] = table[row-1][col] + table[row-1][col-1]

  return grid(table) # use the 'grid' function to format 'table' as a grid
# ------------------------------------------------------------------------------
def parser(command:str) ->str:
  """parse 'command' as integer 'n' before calling 'pascal(n)'"""
  n = parse(command); #inspect()
  assert type(n) is int and n >= 0, "<n> must be a  positive integer"
  return pascal(n)
# ==============================================================================
if __name__ == "__main__":
  userloop(parser, "Enter value for <n>")
# ==============================================================================
