Lab 2: Python 2 (Turtle Blast)

Lab Description:

In this lab, I have created a variable which is imported as turtle and I have learn this from reading chapter 4 of Think Python. In this lab, I use Python to create the variable turtle and import it. From there I also import random because with random, Python can randomly generate a value for my turtle. From there, I open a window for turtle and name my turtle terry, which will be my variable for my turtle. The lab wants the background color to be generated as of red. So then the window bgcolor would be “red”. Then I generate terry to be “white” which labeled in the instructions for lab 2. Now that the simple procedure is done for the variable of turtle, I have to start by giving the amount of steps my variable would need to take and that would be 100, so I placed it in a range of 100. From there, I use a new terminology, randint, which would generate a random value from the imported random with a range from 0-45. This range would be for my turtle variable to turn right and then i port a new variable “distance” for the range that my turtle variable would move forward at a randomly generated value with the term “randint” and lastly I need the turtle variable to move backward at the same value so the variable would need to move forward at x amount of distance and backward with the same x amount of distance which is represented by the variable “distance”.

Code:

import turtle
import random
wn = turtle.Screen()
terry = turtle.Turtle()
wn.bgcolor (“red”)
terry.color (“white”)
for i in range(100):
terry.right(random.randint(0,45))
distance = random.randint(0,150)
terry.forward (distance)
terry.backward (distance)

ScreenShots:

Lab2

Lab2 TurtleBlast

 

Leave a Reply

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