Question: Computer Science Write Python class that takes a string and returns with a valid phone number. Number format is ten-digit numbers consisting of a three-digit
Computer Science
Write Python class that takes a string and returns with a valid phone number.
Number format is ten-digit numbers consisting of a three-digit area code and a seven-digit number.
Clean up different telephone numbers by removing punctuation, and removing incorrect format and the country code (1).
You should throw a ValueError with a string if there are too many or too few digits, or the wrong digits.
For example, the strings: +1 (617) 111-0000, 617-111-0000, 1 617 111 0000, 617.111.0000 should end up with (617) 111-0000
Sample and incomplete starting code:
class Phone:
def __init__(self, raw):
self.number = self._normalize(raw)
def __str__(self) -> str:
def area_code(self) -> str:
def _normalize(self, raw: str) -> str:
Throws a ValueError Exception
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
