1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Paraphin [41]
3 years ago
6

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, including whitespace and punctuation. The loop should break as soon as a pair of different lines is found.

Computers and Technology
1 answer:
mestny [16]3 years ago
8 0

Answer:

Following are the code to this question:

f1=input('Input first file name: ')#defining f1 variable that input file 1

f2=input('Input second file name: ')#defining f2 variable that input file 2

file1=open(f1,'r')#defining file1 variable that opens first files by using open method  

file2=open(f2,'r')#defining file1 variable that opens second files by using open method  

d1=file1.readlines()#defining d1 variable that use readlines method to read first file data

d2=file2.readlines()#defining d2 variable that use readlines method to read second file data

if d1==d2:#defining if block that check file data

   print('Yes')#when value is matched it will print message yes  

   exit# use exit keyword for exit from if block

for j in range(0,min(len(d1),len(d2))):#defining for loop that stores the length of the file  

   if (d1[j]!=d2[j]):#defining if block that check value is not matched

       print('No')#print the message "NO"

       print("mismatch values: ",d1[j]," ",d2[j])#print file values

Output:

please find the attached file.

Explanation:

code description:

  • In the above code, the "f1 and f2" variable is used for input value from the user end, in which it stores the file names. In the next step, the "file1 and file2" variable is declared that uses the open method to open the file.
  • In the next line, the"d1 and d2" variable is declared for reads file by using the "readlines" method.
  • Then, if block is used that uses the "d1 and d2" variable to match the file value if it matches it will print "yes", otherwise a for loop is declared, that prints files mismatch values.

You might be interested in
In the Business world people are often measured by their???
aleksandr82 [10.1K]

Answer: D technical skills

8 0
3 years ago
Web navigation gives the user a sense of control.
Leviafan [203]
1. a.
2. d
3. b
I hope this helps
6 0
4 years ago
Read 2 more answers
*When a computer programmer is finished writing or developing a program, what has to happen first before the computer can unders
Alenkinab [10]

Answer:

C. The source code has to be translated into object code.

5 0
3 years ago
Plato: A university wants to install a client-server network. Which feature do you think is important for them as they set up th
Lana71 [14]

Answer:

its sending emails and low cost to set up

Explanation:

this is how most universities work and how they do things

5 0
3 years ago
In classical conditioning, _____ means that the CS and US are presented closely together, whereas _____ means that the CS is a g
Sav [38]

Answer:

The answer is "stimulus and response"

Explanation:

The classical conditioning, which is used in research, It also used in software and computer systems theory, that design, implementation and checks performance of computer.

  • It also provides the process, by which an initially supportive stimulus helps to elicit an adherence to qualities as opposed to only a biochemical mental workout.
7 0
3 years ago
Other questions:
  • What are the advantages of repeating a header row? check all that apply
    14·1 answer
  • Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation
    6·1 answer
  • Name one app that currently has a positive impact on society and explain why you think it has had a positive effect.
    10·1 answer
  • Help ASAP
    5·2 answers
  • I have to make a online presentation, which program is the best
    10·2 answers
  • Rutherford concluded from his calculations that the volume of an atom is filled with protons, neutrons and electrons. is mostly
    14·1 answer
  • The breastbone or ________________ extends down the chest.
    5·1 answer
  • 1. What is wrong with the following code?
    5·1 answer
  • Explain<br> the three types of periodic<br>maintanance. .​
    10·1 answer
  • A major public university graduates approximately 10,000 students per year, and its development office has decided to build a We
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!