Append Glitch Not Recognizing Inputs

Viewed 38

I was making a slope calculator when I ran into a problem. I took their inputted points, stripped the parentheses, and split at the comma. It gave me an error about not recognizing the term "append". Here is the code:

wtd1 = input("Please enter the coordinates of your first point in (x,y) format. And there is no point in putting in the same thing twice.\n")
wtd1 = wtd1.strip("( )")
wtd1 = wtd1.split(",")
wtd2 = input("Please enter the coordinates of your second point in (x,y) format\n")
wtd2 = wtd2.strip("( )")
wtd2 = wtd2.split(",")
x_points = x_points.append(wtd1[0])
x_points = x_points.append(wtd2[0])
y_points = y_points.append(wtd1[1])
y_points = y_points.append(wtd2[1])
x_points = x_points.sort()
y_points = y_points.sort()
run = x_points[1]-x_points[0]
rise = y_points[1]-y_points[0]
slope = int(rise / run)

The specific error is 'Nonetype' object has no attribute to 'append' on the line with x = x_points.append(wtd[0]). Just an FYI, std stans for 'what to do'

1 Answers

To add data to the arrays 'x_point, y_point', you need to initialize them. All data 'wtd' is converted from string to fractional format. And notice how elements are added to arrays 'x_point, y_point'.

x_points = []#initializing an array
y_points = []#initializing an array

wtd1 = input("Please enter the coordinates of your first point in (x,y) format. And there is no point in putting in the same thing twice.\n")
wtd1 = wtd1.strip("( )")
wtd1 = wtd1.split(",")
wtd2 = input("Please enter the coordinates of your second point in (x,y) format\n")
wtd2 = wtd2.strip("( )")
wtd2 = wtd2.split(",")
x_points.append(float(wtd1[0]))
x_points.append(float(wtd2[0]))
y_points.append(float(wtd1[1]))
y_points.append(float(wtd2[1]))
x_points.sort()
y_points.sort()
run = x_points[1]-x_points[0]
rise = y_points[1]-y_points[0]
slope = float(rise / run)

print(slope)
Related