Question: Create a program called Dif. This program should prompt the user for the names of two text files and compare the contents of the two

Create a program called Dif. This program 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 program should simply output Yes to the console. 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.

These files are the names that contain text for testing.

Text1

Text2

Text3

This is what I have (the "no" part doesn't work) :

name1 = input("Enter the name of file1: ") name2 = input("Enter the name of file2: ")

read1 = open(name1, 'r') read2 = open(name2, 'r')

list1 = read1.readlines() list2 = read2.readlines()

if list1 == list2: print("Yes.") exit

for i in range(0 , min(len(list1), len(list2))): if list1[i] != list2[i]: print("No.") print(list1[i]) print(list2[i])

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!