I am stuck on this problem but cannot figure out why it isn't working as intended. I have a text file with a bunch of x and y coordinates which I need to use to find the average of all x and y values in order to calculate the slope for my regression line. It seems like stamping the individual coordinates works but apparently appending each x or y value to my lists isn't working right as the error I am getting is "ZeroDivisionError: division by zero".
Here's my code:
import turtle
t = turtle.Turtle()
wn = turtle.Screen()
turtle.setworldcoordinates(-100, -100, 100, 100)
wn.bgcolor('lightblue')
t.pencolor('red')
filename = open('data.txt', 'r')
def plotregression():
sum_of_x = []
mean_of_x = sum(sum_of_x) / len(sum_of_x) #doesnt work as intended
sum_of_y = []
mean_of_y = sum(sum_of_y) / len(sum_of_x) #doesnt work as intended
#slope =
for line in filename:
values = line.split()
sum_of_x = sum_of_x.append(values[1])
sum_of_y = sum_of_y.append(values[1])
t.up()
t.goto(int(values[0]), int(values[1]))
t.down()
t.stamp()
t.down()
plotregression()
filename.close()
wn.exitonclick()
I really appreciate any input.
