Midterm Questions-checkpoint.ipynb
Midterm Questions-checkpoint.ipynb_
𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻 1
As you are a student of university now, you need to ensure your assignments
are plagiarism-free. To do this, you decide to design a simple plagiarism
checker. Your checker will take 2 strings as input. Then it will compare
the 2 strings and check how many words they have in common. Then, print the
percentage in common, by calculating:
(No. of words in common / (No of words in string 1 + No of words in string 2)) * 100.
If the calculated plagiarism is greater than or equal to 30%,
print “Plagiarism detected.” Otherwise, print “Good job!”.
Note: you need to compare “words” not individual characters. You can
consider that all characters in both inputs will be in only lowercase or
uppercase.
def plag_checker(input1, input2):
input1 = input1.lower()
input2 = input2.lower()
j = 0
for i in set(input1.split(' ')):
if i in set(input2.split(' ')):
j = j + 1
if j / (len(set(input1.split(' '))) + len(set(input2.split(' ')))) >= 0.3:
return 'Plagiarism detected'
else:
return 'good job'
plag_checker('what do we have in common', 'we do not have anything in common' )
'Plagiarism detected'
Comments
Leave a comment