On day 19 of Angela Yu’s course we use a for loop to create 6 turtle instances called “new_turtle” and append them to a list. I don’t understand how you can have 6 instances with the same name without overwriting? I’ve put the code below
for turtle_index in range(0,6): new_turtle = Turtle(shape = "turtle") new_turtle.color(colours[turtle_index]) new_turtle.penup() new_turtle.goto(-230,y_positions[turtle_index]) turtles.append(new_turtle) for turtle in turtles: random_distance = random.randint(0,10) turtle.forward(random_distance)
submitted by /u/kamcateer
[link] [comments]
r/learnpython On day 19 of Angela Yu’s course we use a for loop to create 6 turtle instances called “new_turtle” and append them to a list. I don’t understand how you can have 6 instances with the same name without overwriting? I’ve put the code below for turtle_index in range(0,6): new_turtle = Turtle(shape = “turtle”) new_turtle.color(colours[turtle_index]) new_turtle.penup() new_turtle.goto(-230,y_positions[turtle_index]) turtles.append(new_turtle) for turtle in turtles: random_distance = random.randint(0,10) turtle.forward(random_distance) submitted by /u/kamcateer [link] [comments]
On day 19 of Angela Yu’s course we use a for loop to create 6 turtle instances called “new_turtle” and append them to a list. I don’t understand how you can have 6 instances with the same name without overwriting? I’ve put the code below
for turtle_index in range(0,6): new_turtle = Turtle(shape = "turtle") new_turtle.color(colours[turtle_index]) new_turtle.penup() new_turtle.goto(-230,y_positions[turtle_index]) turtles.append(new_turtle) for turtle in turtles: random_distance = random.randint(0,10) turtle.forward(random_distance)
submitted by /u/kamcateer
[link] [comments]