Created
July 15, 2013 11:14
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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