for-while loop problem
Hi experts!
Im a newbie Python and sage user.
Im writing a script for draw N random lines in a rectangle of b*h center in axes.
The actual code is:
print('Distribuye N rectas aleatorios de longitud 1 en un rectángulo de b x h centrado en el origen de un par de ejes cartesianos\n')
N=float(raw_input('Número de rectas aleatóreos (N)?:\n'))
b=float(raw_input('Base del rectángulo (b>1)?:\n'))
h=float(raw_input('Altura del cuadrado (h>1)?:\n'))
uniforme_x=RealDistribution('uniform',[-b/2,b/2])
uniforme_y=RealDistribution('uniform',[-h/2,h/2])
lista_x=[uniforme_x.get_random_element() for j in srange(N)]
lista_y=[uniforme_y.get_random_element() for j in srange(N)]
lista_xy = zip(lista_x , lista_y)
lineas=[]
d2=1*1*2
for j in lista_xy:
x1 = j[0]
y1 = j[1]
while d2>1*1:
x2 = uniforme_x.get_random_element()
y2 = uniforme_x.get_random_element()
d2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)
lineas.append([j,(x2,y2)])
grafico=sum(lineas)
grafico.show()
The associated output is a graph of N lines. Each line comes from a different item from the list zip BUT end at the same point (x2, y2). Furthermore the lines have length (d2) greater than 1.
I cant find the error. I know this is a basic question but i hope you can help me.
Waiting for your answers.
Best regards.
Looks to me like you have an issue with brackets and parentheses in the line `lineas.append(j,(x2,y2)]))`