Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Fill in the function problem1. This function should return True if the input string is a valid phone number and False if not. We define

Fill in the function problem1. This function should return True if the input stringis a valid phone numberand False if not. We define a valid phone number as follows:

First, it contains anoptionalarea code (3 digits) followed by 7 digits.

Second, there could be one of several possible formats for the phone number, where the Xs are digits:

(XXX) XXX-XXXX

XXX-XXX-XXXX

XXX-XXXX

ANY other format should not count as a valid phone number. Spaces before or after an otherwise number is considered invalid.

Remember that (, ), - and . are special characters for regular expressions. To search for those characters, you need to precede them with a backslash: \( \), \-, \..

Because we are looking for the entire string to be a phone number, you can either use ^ and $ to force a match to be at the beginning and end of a string, or you can use fullmatch instead of match or search.

Where problem1 is : (you can assume import re is already there)

def problem1(searchstring): """ Match phone numbers.

:param searchstring: string :return: True or False """ pass

Please provide the function and explanation for this ,

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intermediate Accounting

Authors: James D. Stice, Earl K. Stice, Fred Skousen

17th Edition

978-0324592375

Students also viewed these Programming questions