The following function is missing a docstring with pre and post conditions. The objective of this level is to add the missing docstring. If you need to refresh, look at the docstrings information in Section 5.4 on how to add pre and post conditions to code.
#2. Add the missing docstrings. You are to find out what is needed for the function to run (aka pre-conditions) and what the output will be/how the program will be altered by running the function (aka post-conditions). You do not need to add or delete any code in this level, only add the docstrings.
In this level you will create a turtle function that will draw random lines in the window, by moving the turtle to random locations whenever the g key is pressed. This program will also erase all the lines and return the turtle to the middle when the r key is pressed.
Create a function called goto_random(). Inside this function, assign the two global variables random values that are within the window edges(use the randrange function and the constants provided). Note that you will need to use the global keyword (followed by the names of the two variables) inside this function so that you can actually assign the variables values. Editing global variables inside of functions is typically a bad thing to do, but you need to do it here. In a few weeks you will learn a better way to do this.
Create another function called reset(). This function should return the turtle to the center of the window and clear all the pen lines that the turtle has drawn.`` kyra.clear()`` will achieve this.
At the bottom of the program, register the two functions so that they respond to user key presses. The reset() function should be called when the r key is pressed and the goto_random() function should be called when the g key is pressed.
Test to make sure this works. Click in the window, then hit the βgβ key a few times to make sure the turtle moves around. Then hit the βrβ key to ensure the turtle returns to the center and all the lines disappear.
This level is similar to Level 2, except instead of getting random coordinates in response to key presses, you will read a file containing turtle coordinates and then send a turtle around the window using those specific coordinates.
The provided code sets up a world and a turtle, and opens the file with the coordinates for reading. Run the code to make sure it works. Nothing happens yet.