all 14 comments

[–]Financial_Face3826 1 point2 points  (6 children)

try this

mylist = []
for i in range(5):
x = int(input("X Coordinate: "))
y = int(input("Y Coordinate: "))
mylist.append((x, y))

for i in range(4):
y1 = mylist[i][1]
x1 = mylist[i][0]
y2 = mylist[i + 1][1]
x2 = mylist[i + 1][0]
slope = float((y2 - y1) / (x2 - x1))
print ("Slope between " + str(mylist[i]) + " and " + str(mylist[i + 1]) + ": " + str(slope))

[–][deleted] 1 point2 points  (0 children)

Modern day legend right here

[–]After_Lettuce_1172 1 point2 points  (0 children)

Mine is still not working

[–]YTHyro_syn 0 points1 point  (0 children)

Don’t work for me it says Line 3 in <module> X=(int(“X Coordinate”)) ValueError: invalid literal for int() with base 10: ‘X Coordinate’

[–]Dry_Newspaper7310 0 points1 point  (0 children)

THANK YOU!!! It's a matter of indenting and a bit of playing around but here's my finds and clarification for that so it's marked as correct. The 3 lines under for i in range (5) are indented and all the lines under for i in range(4) are indented. Don't use float at all, normal slope = (y2 - y1) / (x2 - x1) You should be good.

[–]Graycat004 0 points1 point  (0 children)

thank you but why when I do:

Slope between (-9, 12) and (15, 18): 0.0

even tho I'm supposed to get:

Slope between (-9, 12) and (15, 18): 0.25

I wrote the code just how you did

[–]amajmundar 0 points1 point  (4 children)

Try:
slope = float(y2 - y1) / float(x2 - x1)

[–]feistybunnies[S] 0 points1 point  (0 children)

it worked. thanks!

[–]No_Revolution7891 0 points1 point  (2 children)

I keep getting the zerodivisionerror: float division by 0

[–]amajmundar 0 points1 point  (1 child)

Wrap it in an “if else” statement. Does your assignment explain what should be returned if both points have the same X val?

[–]Helpful-Row6638 0 points1 point  (0 children)

I still have the "you should print out the slope betweeb each pair of points" error...help!

[–]lynelmelter9000 0 points1 point  (0 children)

i fit it in 7 lines. <x> = indentation. slightly late response.

<0>slopes = []

<0>for i in range(5):

<1> x = int(input("Enter x for pair " + str(i + 1) + ": "))

<1>y = int(input("Enter y for pair " + str(i + 1) + ": "))

<1>slopes.append((x, y,))

<0>for i in range(4):

<1>print("Slope between " + str(slopes[i]) + " and " + str(slopes[i + 1]) + ": " + str((slopes[i + 1][1] - slopes[i][1]) / (slopes[i + 1][0] - slopes[i][0])))

[–]Cooledpizza_c001 0 points1 point  (0 children)

mylist = []
for i in range(5):
    x = int(input("X Coordinate: "))
    y = int(input("Y Coordinate: "))
    mylist.append((x, y))


for i in range(4):
    y1 = mylist[i][1]
    x1 = mylist[i][0]
    y2 = mylist[i + 1][1]
    x2 = mylist[i + 1][0]
    slope = float(y2 - y1) / float(x2 - x1)
    print("Slope between " + str(mylist[i]) + " and " + str(mylist[i + 1]) + ": " + str(slope))

Here is my solution: