how to calculate the distance between multiple points in a list using a loop.
def create_list(x_range,y_range, locations):
generated_list = []
for x in range(locations):
x_range = random.randint(-300,300)
y_range = random.randint(-300,300)
generated_list.append([x_range, y_range])
return generated_list
above creates a random list and I need to calculate the total distance for all points returning back to the beginning using this code:
def calculate_distance(starting_x, starting_y, destination_x, destination_y):
distance = math.hypot(destination_x - starting_x, destination_y - starting_y) # calculates Euclidean distance (straight-line) distance between two points
return distance
here I need to calculate the distance between all points using a loop with the function above, how would I use a loop to calculate the distance between all points