INQ241B
Mobile Apps

Activity 5

Conditionals

  1. Create a new script where the turtle wanders. To do this the turtle should repeatedly move forward and turn a random amount. Be sure that the turtle can turn both left and right.

    wander
  2. Modify the script from the previous activity so that if the turtle reaches the top, bottom, left, or right sides of the screen, it is teleported back to the center. To determine if the turtle has reached an edge of the screen, compare the coordinates of the turtle’s position to the coordinates of the edge of the screen. You can use the actions turtle→xcor and turtle→ycor to get the turtle’s position and the actions turtle→world width and turtle→world height to get the size of the drawing area. To teleport the turtle back to the center, use the turtle→go home action.

Submission

Please show your source code and run your scripts for the instructor or lab assistant.