One function uses xyz, and then I call those variables in another function. the function distance is supposed to take each xyz from readast,and then square, sum, and square root each row. ex 500 600 700 (square each number, add them all up, then square root the sum) It will take that result and display it after the row has ended. However, my numbers in distance are only the last row of numbers in my readast function... any idea why?
def readast():
astlist=open('asteroids.txt','w')
letter=65
for line in range(15):
x=random.randint(1,1000)
y=random.randint(1,1000)
z=random.randint(1,1000)
astlist.write(('\n')+chr(letter)+('\t')+(str(x))+('\t')+(str(y))+('\t')+(str(z)))
letter=letter+1
return astlist,x,y,z
astlist.close()
def distance(astlist,x,y,z):
distlist=open('distance.txt','w')
letter=65
for line in range(15):
x1=x**2
y1=y**2
z1=z**2
equation=math.sqrt(x1+y1+z1)
distlist.write(('\n')+chr(letter)+('\t')+(str(x))+('\t')+(str(y))+('\t')+(str(z)+('\t')+(str(equation))))
letter=letter+1
return distlist
distlist.close()
returnin a function won't be run. You explicitly return one set ofx, y, zvalues in thereturnline inreadast().