Question: Exercise 2 (2 points). Write a function to parse US phone numbers written in the canonical (404) 555-1212 format, i.e., a three-digit area code enclosed

Exercise 2 (2 points). Write a function to parse US phone numbers written in the canonical "(404) 555-1212" format, i.e., a three-digit area code enclosed in parentheses followed by a seven-digit local number in three-hyphen-four digit format. It should also ignore all leading and trailing spaces, as well as any spaces that appear between the area code and local numbers. However, it should not accept any spaces in the area code (e.g., in '(404)') nor should it in the seven-digit local number.\ \ For example, these would be considered valid phone number strings:\ \ '(404) 121-2121'\ '(404)121-2121 '\ ' (404) 121-2121'\ By contrast, these should be rejected:\ \ '404-121-2121'\ '(404)555 -1212'\ ' ( 404)121-2121'\ '(abc) 555-12i2'\ It should return a triple of strings, (area_code, first_three, last_four).\ \ If the input is not a valid phone number, it should raise a ValueError.\ \ The same wrapper function eif_wrapper from Exercise 1 will be used for evaluation.

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 Databases Questions!