0

I have a few coordinates in my turtle graphics that I want the turtle to move between, is it possible for it to move through the list of coordinates one by one and stop at a random one? if I do random.choice(coordinates) the turtle will just move to that coordinate, but I want it to move through the list of coordinates and stop at a randomly chosen one.

coordinates = ((20,-125),(50,-115),(80,-95),(100,-75),(120,-50),(130,-20),(125,20))
irevo
  • 1
  • 2

2 Answers2

0

You should shuffle your list of coordinates :

from random import shuffle
coordinates = shuffle([(20,-125),(50,-115),(80,-95),(100,-75),(120,-50),(130,-20),(125,20)])
for coordinate in coordinates :
    turtle.goto(coordinate)

Take a look at here.

AmirHmZ
  • 516
  • 3
  • 22
0

You could use a slice with a random number

import random
coordinates = ((20,-125),(50,-115),(80,-95),(100,-75),(120,-50),(130,-20),(125,20))
coordinates_pick = coordinates[:random.randint(0,len(coordinates))]
BeneSim
  • 80
  • 5
  • He's going to iterate over all of coordinates not some of them! – AmirHmZ Apr 12 '20 at 09:03
  • Thats exaclty what the OP asked _but I want it to move through the list of coordinates and stop at a randomly chosen one._ The question wasn't how do I shuffle my list but rather how to stop at a random point after going through it one by one. I think this should be the correct anser – Björn Apr 12 '20 at 09:06
  • OP says : **move through the list of coordinates one by one and stop !** , So he wants to move to all of that points one by one ! shuffle will randomize all of list items so at the end turtle will stops on a random one too! – AmirHmZ Apr 12 '20 at 09:15
  • yes what I want to do is for example the pointer to move to each coordinate in the list until it stops at one random point, so like a wheel. – irevo Apr 14 '20 at 12:05