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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!