Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions

Question

Define control and extraneous variables.

Answered: 1 week ago

Question

Why should a business be socially responsible?

Answered: 1 week ago

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago