I wrote my own vector class:
#! /usr/bin/env python3 class V: """Defines a 2D vector""" def __init__(self,x,y): self.x = x self.y = y def __add__(self,other): newx = self.x + other.x newy = self.y + other.y return V(newx,newy) def __sub__(self,other): newx = self.x - other.x newy = self.y - other.y return V(newx,newy) def __str__(self): return "V({x},{y})".format(x=self.x,y=self.y)
I want to determine that V (0,0) is an empty vector, such that it will work: (The first case should return "Vector is empty")
v = V(0,0) u = V(1,2) if u: print (u) else: print("Vector is empty") if v: print(v) else: print("Vector is empty")
source share