Ask Question
26 April, 08:26

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:

+1
Answers (1)
  1. 26 April, 10:34
    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 you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers