Question: 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

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
Get step-by-step solutions from verified subject matter experts
