Ok...so I have this psedecode that I want to follow but it keeps giving me an error so I'm not sure where I went wrong.
Here is the psedecode:
Thanks for helping !!
Here is the psedecode:
Code:
repeat n times
generate random coordinates for new_city
too_close = True
while too_close == True
too_close = False
for each city in the city list so far
if the new_city < distance from city too_close = True generate new random city point break
add new_city to the results list
and here's what I have
def generate_cities(min_x,max_x,min_y,max_y,n,distance):
cities = [ ]
for x in range(n):
x , y = randint(min_x,min_y),randint(max_x,max_y)
too_close = True
while too_close ==True:
too_close = False
for i in cities:
if get_distance(x,y,i[0],i[1]) < distance:
too_close = True
x , y = randint(min_x,min_y),randint(max_x,max_y)
else:
too_close = False
break
cities.append(x,y)
Comment