We can program the computer to behave randomly. Python has a module called random that allows us to simulate random choices.

Guessing

Colorful Random Spirals

Rock-Paper-Scissors

Pick a Card

Roll the Dice

Keleidoscope

Summary

At this point, you should be able to do the following:

  1. Import the random module into your programs.
  2. Use random.randint() to generate a random integer number in a given range.
  3. Use random.choice() to pick a value at random out of a list or array.
  4. Use random.choice() to generate 52 card values from two arrays of strings containing only the faces and suits.
  5. Determine the size of your drawing window with turtle.window_ width() and turtle.window_height().
  6. Move the turtle to any position on the drawing screen with turtle.setpos(x,y).
  7. Use the random.randrange() function to generate a random number in any range.
  8. Find the index of an element in a list or array with the .index() function.
  9. Build a while game loop using a Boolean flag variable like keep_going.
  10. Construct an array of similar types of values, assign values to elements in the array by their index (as in dice[0] = 2), and use array elements like regular variables.
  11. Sort lists or arrays with the .sort() function.
  12. Reflect points about the x- and y-axes by changing the signs of the points’ (x, y) coordinate values.
  13. Change the turtle’s drawing speed with the .speed() function.

Challenges