Detect Plagiarism in files using Python With Source Code

Introduction

Hello Curious Coders,
In this project we are going to discuss how to check the plagiarism between the
contents present in two different text files. In python this can be done using
predefined package difflib but we are going to check it manually. Let’s get into it….

Source Code :

Get Discount on Top Educational Courses

Brand NameDiscount InformationCoupon Codes Link
Educative.io20% discount on Educative courses and plans
W3Schools20% discount on W3Schools courses
KodeKloud10% discount on KodeKloud courses and plans
GeeksforGeeks30% discount on GeeksforGeeks courses
Target Test Prep20% discount on Target Test Prep
Coding Ninjas₹5000 discount on Coding Ninjas courses
Skillshare40% discount on Skillshare
DataCamp50% discount on DataCamp
365 Data Science57% discount on 365 Data Science Plans
Get SmarterFlat 20% discount on Get Smarter courses
SmartKeedaFlat 40% discount on SmartKeeda courses
StackSocial20% discount on StackSocial courses
				
					# import required library
from tkinter import *

# First we need to read the contents of two files
with open('File_1.txt') as f1:
    s1=f1.read().lower().split()
    l1=[]
    for i in s1:
        if i.isalnum():
            l1.append(i)
with open('File_2.txt') as f2:
    s2=f2.read().lower().split()
    l2=[]
    for i in s2:
        if i.isalnum():
            l2.append(i)

# Finding how many words are common in two files
plag_words=len(set(l1).intersection(set(l2)))

# Finding total number of words in two files
total_words=len(l1)+len(l2)

# Formula to calculate the plagarism percent
plag_percent=100-round((total_words-plag_words*2)/total_words*100)

# Displaying the result
result="      The Plagarized Content Percent among two files is "+str(plag_percent)+"%"
if plag_percent30 and plag_percent<=60:
    win= Tk()
    win.geometry("800x200")
    canvas= Canvas(win, width= 700, height= 650, bg="Yellow")
    canvas.create_text(300, 100, text=result, fill="black", font=('Helvetica 15 bold'))
    canvas.pack()
    win.mainloop()
else:
    win= Tk()
    win.geometry("800x200")
    canvas= Canvas(win, width= 700, height= 650, bg="Red")
    canvas.create_text(300, 100, text=result, fill="black", font=('Helvetica 15 bold'))
    canvas.pack()
    win.mainloop()
				
			

Code Explanation :

1. First we read the contents of two files using open() method
2. We read the contents of lines using read() function which return as string.
So we splitted that string into list of words by excluding punctuation marks(,).
3. We extacted the common words from two lists by conveting them to sets.
4. Next we calcualted the length of plagarised words and total words present in two files.
5. Finally we applied a formual there to calculate the plagarised content from two files and printed it on the screen

Output :

Detect plagiarism in files using Python

Find More Projects

ludo game in python using gui and thinkter introduction The “ludo game in python“ project is a simplified digital version of the …

hotel management system in python introduction The Hotel Management System is a simple, interactive GUI-based desktop application developed using Python’s Tkinter library. …

cryptography app in python using gui introduction In the digital age, data security and privacy are more important than ever. From messaging …

portfolio generator tool in python using GUI introduction In today’s digital-first world, having a personal portfolio is essential for students, job seekers, …

interactive story game in python using gui introduction The Interactive story game in python using gUI  is a visually rich, dynamic, and engaging …

maze generator using Python with Pygame Module GUI introduction In this maze generator using Python, realm of logic, problem-solving, and computer science, …

Get Huge Discounts
More Python Projects