<Purpose>
    Used to print seash factoids when user uses 'show factoids'
    command.
    
  <Arguments>
    input_dict: Input dictionary generated by seash_dictionary.parse_command().
    environment_dict: Dictionary describing the current seash environment.
    
    For more information, see command_callbacks.py's module docstring.
    
  <Side Effects>
    Prints factoids onto the screen.
    
  <Exceptions>
    UserError: If user does not type appropriate command.
    ValueError: If user does not provide valid input (integer).
    
  <Return>
    None

def print_factoids(input_dict, environment_dict):
  """
  <Purpose>
    Used to print seash factoids when user uses 'show factoids'
    command.
    
  <Arguments>
    input_dict: Input dictionary generated by seash_dictionary.parse_command().
    environment_dict: Dictionary describing the current seash environment.
    
    For more information, see command_callbacks.py's module docstring.
    
  <Side Effects>
    Prints factoids onto the screen.
    
  <Exceptions>
    UserError: If user does not type appropriate command.
    ValueError: If user does not provide valid input (integer).
    
  <Return>
    None
  """
  
  # User will insert an argument regarding how many factoids should be printed.
  # We have to find what is user argument.
  # User can type any positive number or he can type 'all' to see all factoids.
  dict_mark = input_dict
  try:
    command = dict_mark.keys()[0]
    while dict_mark[command]['name'] != 'args':
      dict_mark = dict_mark[command]['children']
      command = dict_mark.keys()[0]
    args = command
  except IndexError:
    raise seash_exceptions.UserError("\nError, Syntax of the command is: show factoids [number of factoids]/all \n")
  
  # User decided to print all factoids
  if args == 'all':
    print
    for factoid in factoids:
      print factoid
    print
    return
  
  # User can not insert other than integer number.
  try:
    no_of_factoids = int(args)
  except ValueError:
    raise seash_exceptions.UserError("\nYou have to enter number only.\n")
  
  # If number of factoids decided by user is greater than total number of
  # available factoids than whole factoids list is printed.
  if (no_of_factoids > (len(factoids))):
    print "\nWe have only %d factoids. Here is the list of factoids:" % (len(factoids))
    no_of_factoids = len(factoids)
  elif (no_of_factoids <= 0):
    raise seash_exceptions.UserError("\nYou have to enter positive number only.\n")
  
  # 'factoids' list will be shuffled every time for printing random factoids.
  random.shuffle(factoids)
  
  # Factoids will be printed.
  for factoid in factoids[:no_of_factoids]:
    print factoid
  print