Write a script named dif.py. This script should prompt the user for the names of
ID: 3624193 • 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"
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.