Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Your task is to write a function to print valid phone numbers. You need to accept the inputs from the file(input1.txt) and output the

image text in transcribed
1. Your task is to write a function to print valid phone numbers. You need to accept the inputs from the file(input1.txt) and output the valid phone numbers on the console. Format for valid phone numbers is: (xXX) XXX-XXXX XXX-XXX-XXXX where x would be a number. Sample Input: input1.txt Example: Input: 987-123-4567 123 456 7890 (123) 456-7890 Output: 987-123-4567 (123) 456-7890 Hint: You may use regular expressions. (import re) Source Code:- import re filepath = 'inputs/input1.txt' def is Valid(s): Pattern = re.compile("((\\([0-91{3]V)) | [0-9] | D)13))[\\s\\-]?[\\-91{3}[\\s\\-]?[0-91{4}$") Pattern1 = re.compile("((\\([0-9]13]V) | [0-9]13))[\\-]?[\\0-91{3][\\s\\-]?[0-91{4}$") if (Pattern.match(s) or Pattern1.match(s)): return s with open(filepath) as fp: line = fp.readline() cnt = 1 while line: line = fp.readline()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions