function cleanRow() while (frontIsClear()) safeTakeBall(); move();
Use if(ballsPresent()) to have Karel only pick up a ball if one actually exists on that space.
Students looking for "all answers" typically want a repository of working code for every single exercise.