Python Forum
Length of a path in a 2-tuple.
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Length of a path in a 2-tuple.
#1
Some homework that I have been struggling on mainly because I am unsure how to proceed. I have all the formulas I need but I haven't been able to find a useful online tutorial for how to get the necessary information out of a 2-tuple.

print (pathLength2d ([(0,0), (1,1)])) 
import math

def length (v):

    """ Length of a vector in 2-space.

    Params: v (2-tuple) vector in 2-space
    Returns: (float) length
    """
    number = 0
    for i in range(len(str(v))):
        number += v[i]**2
    return math.sqrt(number)
I know that's an error as it's trying to multiply an index of (0,0) by itself. I'm not asking for a full out solution, but a pointer in the right direction.

Thanks!
Reply


Messages In This Thread
Length of a path in a 2-tuple. - by PythonNerd - Sep-29-2016, 10:47 PM
RE: Length of a path in a 2-tuple. - by micseydel - Sep-29-2016, 10:55 PM
RE: Length of a path in a 2-tuple. - by PythonNerd - Sep-30-2016, 01:25 AM
RE: Length of a path in a 2-tuple. - by ichabod801 - Sep-29-2016, 10:56 PM
RE: Length of a path in a 2-tuple. - by Ofnuts - Sep-30-2016, 09:36 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020