Okay, so you probably haven't seen my previous question, whats wrong with this code. For those who have, you know what I'm talking about. If not, heres what I have to do.
We have to do this using object-oriented coding. We don't have to use classes, but I just chose to do so. This also needs to happen in turtle graphics. Heres my code:
The only problem is that I keep getting sent errors, which I don't understand. If so, can you take a look at my code and try to tell me what I'm doing wrong. Much appreaciated. Also, if there's an easier way to do this without using classes, that would be great. Thanks.
Randomly place a pyramid (yellow, large turtle) on the screen. Have a second turtle move
randomly until it is close to the pyramid. Stop the seeking turtle once it has found the pyramid.
randomly until it is close to the pyramid. Stop the seeking turtle once it has found the pyramid.
Code:
from turtle import *
from random import *
def find_the_pyramid():
class Pyramid(Turtle()):
color="yellow"
shape="triangle"
shapesize=4
def __init__(self,color,shape,shapesize):
self.color=color
self.shape=shape
self.shapesize=shapesize
self.goto(randint(-100,100),randint(-100,100))
self.goto(randint(-100,100),randint(-100,100))
class Lost_Turtle(Turtle()):
name="Kirk"
color="brown"
shape="turtle"
shapesize=2
def __init__(self,name,color,shape,shapesize):
self.name=name
self.color=color
self.shape=shape
self.shapesize=shapesize
Sphinx=Pyramid("yellow","triangle",5)
Billy=Lost_Turtle("Billy","blue","turtle",3)
while(Billy.distance(Sphinx)>20):
Billy.forward(randint(40,80))
Billy.right(randint(0, 360))
find_the_pyramid()
Comment