Activity 2: Find the Pyramid
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.
So here's my code.
from random import*
from turtle graphics*
class pyramid:
class lost_turtle:
while (lost_turtle.di stance(pyramid) <25):
My teacher said that my while loop does not work because lost_turtle and pyramid only exist in their class and I can't call it. Is there any way to fix this without putting it in one big function or putting it in two files? Help, please!
Also, tell me if you see any general errors. I just started this programming shebang, so don't be too harsh. 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.
So here's my code.
from random import*
from turtle graphics*
class pyramid:
pyramid=Turtle( )
pyramid.shape(" triangle")
pyramid.color(" yellow")
pyramid.shapesi ze(4)
pyramid.up()
pyramid.goto(ra ndint(-300,300), randint(-300,300)
pyramid.down()
pyramid.shape(" triangle")
pyramid.color(" yellow")
pyramid.shapesi ze(4)
pyramid.up()
pyramid.goto(ra ndint(-300,300), randint(-300,300)
pyramid.down()
class lost_turtle:
lost_turtle=Tur tle()
lost_turtle.sha pe("turtle")
lost_turtle.col or("brown")
lost_turtle.sha pe("turtle")
lost_turtle.col or("brown")
while (lost_turtle.di stance(pyramid) <25):
lost_turtle.fd( randint(10,33))
lost_turtle.rt( randint(0,360))
lost_turtle.rt( randint(0,360))
My teacher said that my while loop does not work because lost_turtle and pyramid only exist in their class and I can't call it. Is there any way to fix this without putting it in one big function or putting it in two files? Help, please!
Also, tell me if you see any general errors. I just started this programming shebang, so don't be too harsh. Thanks
Comment