Question: This is in python #A common problem in academic settings is plagiarism #detection. Fortunately, software can make this pretty easy! # #In this problem, you'll
This is in python
#A common problem in academic settings is plagiarism
#detection. Fortunately, software can make this pretty easy!
#
#In this problem, you'll be given two files with text in
#them. Write a function called checkplagiarism with two
#parameters, each representing a filename. The function
#should find if there are any instances of or more
#consecutive words appearing in both files. If there are,
#return the longest such string of words in terms of number
#of words, not length of the string If there are not,
#return the boolean False.
#
#For simplicity, the files will be lowercase text and spaces
#only: there will be no punctuation, uppercase text, or
#line breaks.
#
#We've given you three files to experiment with. filetxt
#and filetxt share a series of words: we would expect
#checkplagiarismfiletxt "filetxt to return the
#string if i go crazy then". filetxt and filetxt
#share two series of words, and one series of words:
#we would expect checkplagiarismfiletxt "filetxt
#to return the string "i left my body lying somewhere in the
#sands of time". filetxt and filetxt do not share any
#text, so we would expect checkplagiarismfiletxt
#"filetxt to return the boolean False.
#
#Be careful: there are a lot of ways to do this problem, but
#some would be massively time or memoryintensive. If you
#get a MemoryError, it means that your solution requires
#storing too much in memory for the code to ever run to
#completion. If you get a message that says "KILLED", it
#means your solution takes too long to run.
#Add your code here!
def checkplagiarismfilename, filename:
with openfilename, r as file openfilename, r as file:
text filereadsplit
text filereadsplit
longestmatch
currentmatch
for word in text:
if word in text:
currentmatch.appendword
else:
if lencurrentmatch lenlongestmatch:
longestmatch currentmatch
currentmatch
if lencurrentmatch lenlongestmatch:
longestmatch currentmatch
if lenlongestmatch:
return joinlongestmatch
else:
return False
#Below are some lines of code that will test your function.
#You can change the value of the variables to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print:
#if i go crazy then
#i left my body lying somewhere in the sands of time
#False
printcheckplagiarismfiletxt "filetxt
printcheckplagiarismfiletxt "filetxt
printcheckplagiarismfiletxt "filetxt
I receive this output:
if i go crazy then
i left my body lying somewhere in the sands of time i watched the world float to the
False
the part where it says "I watched the world float to the is not supposed to be there, how can I fix this?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
