def make_variants(variable, robot_file, possibilities):
    """Makes variants of the file robot_file  with the constant variable
    changed for each possibility.

    e.g. if the variable is "ELEPHANTS" and the possibilities are [1, 2, 3],
    this will find the line
    ELEPHANTS = 3
    in robobt_file and make a copy of the file for each value in possibilities.
    1.py will have ELEPHANTS = 1, 2.py will have ELEPHANTS = 2, etc.

    Raises IndexError if the variable name is not found in the file robot_file.
    The line assigning the constant variable must be the first line in that
    file has the variable name in it.
    """
    filenames = []
    with open(robot_file, 'r') as f:
        lines = f.readlines()
    for i, line in enumerate(lines):
      if variable in line:
          break
    else:
      raise IndexError('variable name %s is not found in file %s' % (variable, robot_file))
    assert '=' in line
    for p in possibilities:
        varandp = variable + str(p)
        lines[i] = "%s = %s\n" % (variable, p)
        filenames.append(varandp)
        with open(varandp, 'w') as pfile:
            for line in lines:
                pfile.write(line)
    return filenames