Question
python. each function must contain a doc string. each function docstring should include description of function's purpose, name, type, and purpose of each parameter and
python. each function must contain a doc string. each function docstring should include description of function's purpose, name, type, and purpose of each parameter and type and meaning of functions return value. please show screenshot in powershell
redact file: This function takes a string filename. It writes a new file that has the same contents as the argument, except that all of the phone numbers are redacted. Assume that the filename has only one period in it. The new filename is the same as the original with redacted' added before the period. For instance, if the input filename were 'myfile.txt', the output filename would be myfile redacted.txt'. Make sure you close your output file. The first hard task in this function is to make the output filename from the input filename that was passed in. You can break it into two pieces by splitting on the dot or by using the index method and slicing. Then put it back together again using string concatenation. We are also working with files in this one. To open a file with a filename stored in the variable fname, in read mode use the open function as such: fp - open(fname). You will need to open the output file in write mode: open(I name, 'W'). Then you can traverse the input file line-by-line with this syntax: for line in fps. To write to an output file, use the write method: fp_out.write(line). plagiarism: This Boolean function takes two filenames. If any line occurs in both files, return True. If not, return false. I suggest using nested loops. With nested loops, we call the loop that is in the body of the other loop, the "inner loop". The loop that contains the inner loop is the "outer loop". Open the second file inside the outer loop: for linel in filel: file2 = open(fname2) for line2 in file2: Python only lets you read the file once per open, so you need this order of instructions. Make sure your return false is outside of both loops. Otherwise, you will only compare the first two lines of the files. Make sure you close the file that gets read repeatedly after the inner loop but still inside the outer loop. count_word: This function takes a filename and a keyword. Return the number of times the keyword occurs in the file. Initialize a variable to keep track of the number of times the keyword appears. Traverse the file by line. Use the count method on each line to find the number of times the keyword appears in it and add that amount to the variable.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started