maxHList = [(5,3),(7,4),(9,5)]
totalH = 0
maxH = 0

x = 0

while x < len(maxHList):
    totalH = math.sqrt(pow(maxHList[x+1][0] - maxHList[x][0],2) + pow(maxHList[x+1][1] - maxHList[x][1],2))
    maxH += totalH
    x += 1

I am going +1 over the list length and i get this error but if i say

while x < len(maxHList)-1:

then i dont ge the correct result

Use

for x in range(len(maxHList)):
  ...

and forget about x=0, x+=1, or use

for x in range(-1, len(maxHList)):
  ...

depending on the desired result (sum 2 distances or 3 distances).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.