Lab 2 : Turtle Blast

Description: 

This lab apply the knowledge learned in class and and the previous labs to create and image using the  turtle and random module, once you have import the module, you have to give the program the instruction using variable to create the background and the pen color. But the most important part is to tell the program where to go, and how many times to do it, using the range function in the for loop.


Code:

import turtle
 import random
 wn = turtle.Screen()
 wn.bgcolor("red")
 alex = turtle.Turtle()
 alex.pencolor("white")
 for num in range(100):
 n = random.randint(0,45)
 distance = random.randint(0,150)
     alex.right(n)
     alex.forward(distance)
     alex.backward(distance)


Screenshot:

Turtle blast

Leave a Reply

Your email address will not be published. Required fields are marked *