<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _add(self, sprite, index = None):
 """add one sprite at a time. used by add_child. split them up so that it would be possible specify the index externally"""

        if sprite == self:
            raise Exception("trying to add sprite to itself")

        if sprite.parent:
            sprite.x, sprite.y = self.from_scene_coords(*sprite.to_scene_coords())
            sprite.parent.remove_child(sprite)

        if index is not None:
            self.sprites.insert(index, sprite)
        else:
            self.sprites.append(sprite)
        sprite.parent = self