+1 (315) 557-6473 

Implement String Functions in The Python Assignment Solution.


Instructions

Objective
Write a python assignment program to implement string functions.

Requirements and Specifications

Introduction. This homework is intended to give you practice with string indexing, slicing, and methods, and file I/O and traversing files by line.
Instructions. Create a module named strings.py. Below is the spec for six functions. Implement them and upload your module to the Hw6 D2L Assignments folder.
Testing. Download test_strings.py and put it in the same folder as your strings.py module and the auxiliary testing files. Run it from the command line to see your current correctness score. Each of the six functions is worth 16.7% of your correctness score. You can examine the test module in a text editor to understand better what your code should do. The test module is part of the spec. The test file we will use to grade your program may be different but if your code passes the one provided, it will pass the one we use.
Documentation. Your module must contain a header docstring containing your name, your section leader’s name, the date, ISTA 130 Hw6, and a brief summary of the module. Each function must contain a docstring. Each function docstring should include a description of the function’s purpose, the name, type, and purpose of each parameter, and the type and meaning of the function’s return value.
Source Code
def US_to_EU(s):
    parts = s.split('/')
    replaced = [parts[1], parts[0], parts[2]]
    return '.'.join(replaced)
def is_phone_num(s):
    if len(s) != 12:
        return False
    for i in range(12):
        if i == 3 or i == 7:
            if s[i] != '-':
                return False
        else:
            if not s[i].isdigit():
                return False
    return True
def redact_line(line):
    for i in range(len(line) - 12):
        if ((i == 0 or line[i - 1] == ' ') and line[i + 12] in ' \n' and is_phone_num(line[i:i + 12])):
            line = line[:i] + line[i:].replace(line[i:i + 12], "XXX-XXX-XXXX", 1)
    return line
def redact_file(file):
    fin = open(file, 'r')
    content = fin.readlines()
    dot_index = file.index('.')
    redacted_filename = file[:dot_index] + '_redacted' + file[dot_index:]
    fout = open(redacted_filename, 'w')
    for line in content:
        fout.write(redact_line(line))
    fin.close()
    fout.close()
def plagiarism(filename1, filename2):
    f1 = open(filename1, 'r')
    f1_lines = f1.readlines()
    f2 = open(filename2, 'r')
    f2_lines = f2.readlines()
    for line1 in f1_lines:
        for line2 in f2_lines:
            if line1 == line2:
                f1.close()
                f2.close()
                return True
    f1.close()
    f2.close()
    return False
def count_word(filename, word):
    f = open(filename, 'r')
    counter = 0
    for line in f.readlines():
        if len(line) < len(word):
            continue
        for i in range(len(line) - len(word) + 1):
            matches = True
            for j in range(len(word)):
                if line[i + j] != word[j]:
                    matches = False
                    break
            if matches:
                counter += 1
    return counter