# ==============================================================================
"""MULTABLE : print a (start,stop,step) slice of the multiplication table"""
# ==============================================================================
__author__  = "Christophe Schlick modified by Philippe Blasi"
__version__ = "4.0" # include (start, stop, step) parameters
__date__    = "2022-11-12"
__usage__   = """
User input: <start,stop,step>
            - start:int = start value for the multiplication table
            - stop:int = stop value for the multiplication table
            - step:int = step value for the multiplication table
App output: multiplication table from 'start*start' to 'stop*stop' """
# ==============================================================================
from ezCLI import *
# ------------------------------------------------------------------------------
def multable(start:int, stop:int, step:int) -> str:
  """return a string containing a (start,stop,step) slice of multable"""
  # create a list of integer values for the first row and first col
  values = list(range(start, stop+1, step)); #inspect()
  # create 'table' as a matrix of integers
  table = [[p*q for q in values] for p in values]; #inspect()
  return grid(table) # use the 'grid' function to format 'table' as a grid
# ------------------------------------------------------------------------------
def parser(command:str) -> str:
  """parse 'command' as (start,stop,step) values before calling 'multable'"""
  start, stop, step, *args = parse(command); #inspect()
  assert not args, "only three arguments allowed" # args must be empty
  assert type(start) is int and start > 0, "%s : invalid <start> value" % start
  assert type(stop) is int and stop >= start, "%s : invalid <stop> value" % stop
  assert type(step) is int and step > 0, "%s : invalid <step> value" % step
  return multable(start, stop, step)
# ==============================================================================
if __name__ == '__main__':
  userloop(parser, "Enter <start> <stop> <step>")
# ==============================================================================
