Turtle - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Turtle (/thread-6727.html) |
Turtle - SmokeyTheApe - Dec-05-2017 I really need a second pair of eyes looking at this because its giving me an AttributeError and I can't find it myself. What I'm trying to do is to have N number amount of turtles bouncing off of the window border. import turtle import random import math SIZE = 500 NUM_TURTLES= 10 # set up the window window = turtle.Screen() window.setup(SIZE, SIZE) window.title("Turtle Bounce") # create a turtle turtle = [] for i in range(NUM_TURTLES): murtle = turtle.Turtle() murtle.penup() x, y = random.randit(-100,100), random.randint(-100,100) murtle.goto(x,y) turtles.append(murtle) # point turtle in random direction dx = random.randint(2,5) flip = random.choice([-1, 1]) dx *=flip dy = random.randint(2,5) flip = random.choice([-1, 1]) dy *=flip window.tracer(2, 30) while True: # infinite loop for i in range(NUM_TURTLES): murtle = turtles[i] # make sure murtle didn't leave the window x, y = murtle.position() # if the turtle hits a wall, move her in a random direction if x < -SIZE/2 or x > SIZE/2: dx = -dx if y < -SIZE/2 or y > SIZE/2: dy = -dy murtle.forward(10) # determine heading based on dx and dy heading = math.atan2(dy, dx) heading = (180/math.pi) * heading murtle.setheading(heading) murtle.forward(5) RE: Turtle - buran - Dec-05-2017 Please, post full traceback that you get in error tags. Not all of us want to install turtle package and the traceback itself should be pretty clear in this case RE: Turtle - SmokeyTheApe - Dec-05-2017 Ahh so sorry about that I forgot to include it!
RE: Turtle - buran - Dec-05-2017 on line 14 you overwrite turtle module and after it name turtle refer to a list object. Just use different name for the list.EDIT: actually it looks like you want the list to be turtles , not turtle . So it's simply typo
|