Please answer this question using python programming only and provide a screen short for the code.
Reading: P4E 7; Tut 7.2, 7.2.1
Upload an original Python script that satisfies the following criteria:
It has at least two functionsFunction 1:
This function has one parameter, a string containing the path to an existing text file that will be read by your function
Using a with statement, the function opens the file indicated by the parameter for reading
The function counts the number of lines in the file that contain the letter "j" (a for loop is your friend)
The function returns the final count of lines containing "j"
Function 2:This function has two parameters:
a string containing the path where a text file will be written by your function (if a file already exists at that location, it will be overwritten)
an integer containing a count that will be written to the file
Using a with statement, the function opens the file indicated by the first parameter for writing
The function writes the count in the second parameter to the file
The function returns None implicitly (in other words, it has no return statement)
It has an if __name__ == '__main__': statement that does the following:
Calls the first function, passing a filename as an argument, and captures the return value in a variable
Calls the second function, passing another filename and the result of the first function as arguments
The script adheres to the style guide; this includes, among other things, having a script docstring and function docstrings.
def function1(fileName): with open(fileName) as f: count = 0 for line in f: if 'j' in line: count += 1 print('J appears', count, 'times') def function2(fileName, count): with open(fileName, 'w') as f: f.write('Count: ' + str(count)) if __name__ == '__main__': c = function1('input.txt') function2('output.txt', c)
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.
Get Answers For Free
Most questions answered within 1 hours.