Write a python program that prompts 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 scripts should simply output “Yes”. If they are not, the program 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. There are other solutions to this problem but none of them are working for me!
#Please provide in comments if this does not fulfill the requirements. If there is any error, i can fix it file1=input('Enter name for 1st file: ') file2=input('Enter name for 2nd file: ') f=open(file1) file1Lines=f.readlines()#read all lines in a list called file1lines f.close() f=open(file2) file2Lines=f.readlines()#read all lines in a list called file2lines f.close() check=True for i in range(min([len(file1Lines),len(file2Lines)])):#loop will run until one of the file is over if file1Lines[i].strip()!=file2Lines[i].strip():#if the lines are different print('The lines that differ: ')#print those lines print(file1Lines[i]) print(file2Lines[i]) check=False break if check: print('Yes')
Get Answers For Free
Most questions answered within 1 hours.