Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Zombie:
- def __init__(self,h,s,p):
- self.health = h
- self.size = s
- self.position = p
- def __str__(self):
- return("Zombie has health: " + str(self.health) +
- ", size: " + str(self.size) +
- ", position: " + str(self.position))
- def __lshift__(self, other):
- '''returns an offspring that has health and size that averages the parents '''
- h = (self.health + other.health) / 2
- s = (self.size + other.size) /2
- p = self.position
- return Zombie(int(h),int(s),p)
- def __xor__(self, other):
- ''' returns T/F whether 2 zombies share same position '''
- return( self.position == other.position)
- z1=Zombie(100,250,0)
- z2=Zombie(10,200,0)
- if z1^z2 :
- offspring = (z1 << z2)
- print("New Zombie: " + str(offspring))
Advertisement
Add Comment
Please, Sign In to add comment