Ask Question
30 September, 21:50

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. Below are examples of the program input and output along with relevant files:

+5
Answers (1)
  1. 30 September, 22:17
    0
    1

    Created on Nov 3, 2018 @author: ASLand

    7import atexit

    #Read, nanes of both files

    Rrintll"Enter tvo files to be compared below

    userliamel input ("Enter the nome of the first file: ")

    userliame2 input ("Enter the name of the second file: ")

    ROpen each file

    f1 - open (userNamel, r')

    @17 f2 = opan (useriame 2,)

    tread all the lines into a list

    d1 f1. readlines ()

    d2 f2. readlines ()

    re equivalent, print "Yes" else pri

    oiterate, and conpare

    #11

    the

    y

    if dl = = d2:

    print ("Yes")

    atexit

    elif for i in range (@, min (len (d1), len (d2))):

    if di[i]!=d2[i]:

    PCint ("No")

    print (d1[i])

    pcint (d2[])
Know the Answer?
Not Sure About the Answer?
Find an answer to your 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 ...” in 📗 Engineering if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers