Writing a simple program that strips punctuation from a phone number and returns just the digits in a string:
number = Phone("(223) 456-7890")
print(number.number)
---> should return "2234567890"
The below code does this when '()' is added to the call, otherwise it gives a Bound Method error (understandable).
Issue is that the test suite wants it to return on number.number
(no parens)
Checked the docs on this and various S.O. answers and have tried self.number = ""
in the init method, then trying to load this variable with my results and return that, but that didn't seem to do anything. Any help would be appreciated thx
class Phone (object):
def __init__(self, phone_number):
self.phone_number = phone_number
#self.number = ""
def number(self):
punctuation = ['\'', '+', '(', ')', '-', '.',',',' ']
cpn = list(self.phone_number)
[cpn.remove(item) for item in punctuation if item in cpn]
self.number = ''.join(cpn)
return self.number