Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. class Vector2D:
  2.  
  3. def __init__(self,x,y):
  4. self.x = x
  5. self.y = y
  6.  
  7. def __add__(v1,v2):
  8. suma = v1.x + v2.x
  9. suma2 = v1.y + v2.y
  10. return Vector2D(suma,suma2)
  11.  
  12. def __str__(self):
  13. return '(%s,%s)' % (self.x,self.y)
  14.  
  15. def __sub__(v1,v2):
  16. resta = v1.x - v2.x
  17. resta2 = v1.y - v2.y
  18. return Vector2D(resta,resta2)
  19.  
  20. def productoesc(v1,v2):
  21. mult = v1.x + v2.x
  22. mult1 = v1.y + v2.y
  23. mult2 = mult * mult1
  24. return mult2
  25.  
  26.  
  27. v1 = Vector2D(3,10)
  28. v2 = Vector2D(6,8)
  29.  
  30. print v1+v2
  31. print v1-v2
  32. print productoesc(v1,v2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement