import sys import re def write_answer(answer): with open(output_file, 'a') as file: file.write(answer+'\n') input_file = 'test.in' output_file = 'test.out' # input_file = sys.argv[1] # output_file = sys.argv[2] # pattern = re.compile(r'^[0-9]') pattern = re.compile(r'^(?!)\d-\d{3}-\d{5}-\d{4}$') # 46773 4323 # 2 - ABC # 3 - DEF # 4 - GHI # 5 - JKL # 6 - MNO # 7 - PQRS # 8 - TUV # 9 - WXYZ with open(output_file, 'w') as readed_output_file: with open(input_file, 'r') as readed_input_file: for row_input_file in readed_input_file: if pattern.match(row_input_file): write_answer('yes') else: write_answer('no')