Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a script named dif.py. This script should prompt the user for the names of

ID: 3624189 • Letter: W

Question

Write a script named dif.py. This script should prompt the user for the names of two text files and compare the contents of the two files to see if they are the same. If they are, the script should simply output "Yes". If they are not, the script should output "No", followed by the first lines of each file that differ from each other. The input loop should read and compare lines from each file. The loop should break as soon as a pair of different lines is found. HELP!! PLEASE I have worked on this all week.

Explanation / Answer

test_lines = open("README.txt").readlines()
correct_lines = open("README.txt").readlines()

for test, correct in zip(test_lines, correct_lines):
    if test != correct:
        print "No, Different Lines Found :)"
        print "First file contain %r While seocnd contain %r." % (test, correct)
        break
else:
    len_diff = len(test_lines) - len(correct_lines)
    if len_diff > 0:
        print "Test file had too much data."
    elif len_diff < 0:
        print "Test file had too little data."
    else:
        print "Yes"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote