Hello,
I have this exercise :
Rewrite the distance function from chapter 5 so that it takes two Points as
parameters instead of four numbers.
I have this solution :
class Point:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def distance(p1,p2):
dx = p2.x - p1.x
dy = p2.y - p1.y
dsquared = dx**2 + dy**2
result = dsquared**0.5
return result
P1 = Point()
P1.x = 3
P1.y = 3
P2 = Point()
P2.x = 6
P2.y = 7
result = distance (P1,P2)
print result
Is this the correct solution ?
Roelof
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor