As usual, create two directories for today's class. Create a
directory called lecture14
under activities, and
a directory called lab14
under labs.
Time to learn a new module! This module lets us generate random numbers, which we can then use within out programs.
Create a file called how_random.py
in your
lecture14 directory. Write a function that uses the
turtle module, and draws a line a random distance (and
location) from the origin. You should do this by generating two
random integers, and going to that location on the screen.
Write another function called euclidean_distance
, which
takes 2 integer parameters (x and y), and returns the distance that
the point is from the origin (0,0).
Using these two functions, write a for loop that draws some number of
random lines radiating from the center of the turtle window. Compute
and write (using turtle.write
)
the disance from the origin the end point of the line is.
Your for loop should also compute the average distance from the center your set of points are. Print this average to the terminal. Run your program multiple times. Does this average seem random? Does the distribution of points seem random?