Is this what you needed?
class Phone():
def __init__(self, name, area_code, number, is_active=True):
self.name = name
self.area_code = area_code
self.number = number
self.is_active = is_active
def __str__(self):
return str(self.area_code) + "-" + str(self.number)[:3]+ '-'+ str(self.number)[3:] + ' ' + "(" + self.name + ")"
def __repr__(self):
return self.name + ','+ str(self.area_code) + ',' + str(self.number)
def __eq__(self, other):
return self.area_code == other.area_code and self.number == other.number
def activate(self):
self.is_active = True
def deactivate(self):
self.is_active = False
Now corrected: assume number is a seven-digit integer with no leading 0/1
solved How can I add hypen? [closed]