this is my code:
class personData ():
def __init__(self, age, spouse = None, children = 0):
self.age = age
self.children = children
self.spouse = spouse
if self.spouse == None:
del self.spouse
print "A %s year old person" % str(self.age)
def marries(self, name):
if self.spouse == None:
self.spouse = name
else:
try:
self.marries(name)
except Exception as detail:
print "spouse exists:", self.spouse
def divorces(self):
if self.spouse == None:
raise AttributeError, " Not married, divorce impossible"
what I trying to do is:
def divorces(self):
if self.spouse != None: ## thats mean the person has a spouse,
self.spouse = None ## I think that should remove the spouse, right?
Here should come exception if we call divorce again, because the spouse is removed.
Let's say my:
person = personData(30, 'Sue')
person.spouse would be Sue, if I call person.marries('Anna') an exception is raised, now if I call person.divorce() it will remove the spouse ('Sue'). what I'm stuck at is when I call person.divorce() it should raise exception saying that "no spouse exist" and I'm unable to do that, any help would be appreciated.