Skip to content

Instantly share code, notes, and snippets.

@Stealthii
Created July 15, 2013 11:14
Show Gist options
  • Select an option

  • Save Stealthii/5999226 to your computer and use it in GitHub Desktop.

Select an option

Save Stealthii/5999226 to your computer and use it in GitHub Desktop.
Work for capital markets academy today, looking at Vector class and Schedular class so far.
#!/usr/bin/env python
class Scheduler():
event = ""
dow = ""
dow_list = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"]
def __init__(self, event, dow):
self.event = event
self.dow = dow
def returnindex(self):
return (self.dow_list.index(self.dow))
def getevent(self):
return self.event
def __str__(self):
return str(self.event)
def __cmp__(self, other):
if (self.returnindex() < other.returnindex()):
return(-1)
elif (self.returnindex() == other.returnindex()):
return(0)
else:
return(1)
s = Scheduler("Party at Sara's", "Saturday")
s2 = Scheduler("Party at Harry's", "Friday")
if (s < s2):
print s.getevent()
elif (s == s2):
print s.getevent(), s2.getevent()
else:
print s2.getevent()
#!/usr/bin/env python
class Vector():
def __init__(self, a, b):
self.a = a
self.b = b
def __add__(self, other):
return (Vector(self.a + other.a, self.b + other.b))
def __sub__(self, other):
return (Vector(self.a - other.a, self.b - other.b))
def __mul__(self, other):
return (Vector(self.a * other.a, self.b * other.b))
def __div__(self, other):
return (Vector(self.a / other.a, self.b / other.b))
def __str__(self):
return 'Vector (%d, %d)' % (self.a, self.b)
vector1 = Vector(2, 4)
vector2 = Vector(3, 6)
vector3 = vector1 + vector2
print vector3 - Vector(1,2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment