Using Random NumbersΒΆ

We can generate random numbers in Python using the randrange function in the random library. This function takes an optional starting value (inclusive) and the ending value for the range (exclusive). We can use random numbers in games to add an element of chance. We can also use random numbers to move the turtle to random positions as shown below. We are using conditionals to alternate the drawing color each time the turtle moves.

Can you modify the code above to use 3 different colors? You can use num % 3 to give you 3 possible results.

You have attempted of activities on this page