unsupported operand types??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flapjacks
    New Member
    • Apr 2010
    • 1

    unsupported operand types??

    Code:
    line1 = ((0.0, -1.0), (1.0, 1.0), (2.0, 3.0), (3.0, 5.0), (4.0, 7.0), (5.0, 9.0), (6.0, 11.0), (7.0, 13.0), (8.0, 15.0), (9.0, 17.0))
    line2 = ((0.0, 2.0), (1.0, 1.0), (2.0, 0.0), (3.0, -1.0), (4.0, -2.0), (5.0, -3.0), (6.0, -3.0), (7.0, -5.0), (8.0, -6.0), (9.0, -7.0))
    num1 = str(len(line1))
    num2 = str(len(line2))
    x1 = str(line1[0][0]-line1[1][0])
    y1 = str(line1[0][1]-line1[1][1])
    m1 = (y1/x1)
    b1 = (y1 - m1*x1)
    x2 = str(line2[0][0]-line1[1][0])
    y2 = str(line2[0][1]-line1[1][1])
    m2 = (y2/x2)
    b2 = (y2 - m2*x2)
    x3 = ((b2 - b1) / (m1 - m2))
    y3 = (m2*x2)
    s = "line 1 information = number of points in line: " & num1 \
        + " slope: " & str(m1) & " y intercept: " & str(b1) & \
        "line 2 information = number of points in line: " & num2 & \
        " slope: " & str(m2) & " y intercept: " & str(b2) & \
        " line intersection: (" & str(x3) & "," & str(y3) & ")"
    Traceback (most recent call last):
    File "C:/Users/owner/Documents/hw16.py", line 7, in <module>
    m1 = (y1/x1)
    TypeError: unsupported operand type(s) for /: 'str' and 'str'
    Last edited by bvdet; Apr 22 '10, 06:06 PM. Reason: Add code tags
  • Curly Joe
    New Member
    • Apr 2010
    • 1

    #2
    m1 = (y1/x1)
    TypeError: unsupported operand type(s) for /: 'str' and 'str'
    You are trying to divide two strings. You must use numbers, so convert to an integer or float before dividing.

    Comment

    Working...