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
Which of the following countries have mixed-market economy
timurjin [86]

Answer:

B

Explanation:

An economic system in which both the private enterprise and a degree of state monopoly (usually in public services, defense, infrastructure, and basic industries) coexist. All modern economies are mixed where the means of production are shared between the private and public sectors. Also called dual economy.

6 0
3 years ago
A ____ is a statement specifying the condition(s) that must be true before the function is called.
Trava [24]

Answer: Precondition

Explanation: Precondition statement is the statement that has the condition for the particular program that has to be correct or true before the execution otherwise the condition can result as undefined. This statement checks that there is no error in the statement  before the function gets called. Similarly post condition is for the checking of the statement after being executed.

3 0
3 years ago
What is the difference between HTML and XML?
Luba_88 [7]

Explanation:

HTML displays data and describe the structure of a webpage while XML stores and transfers data.

7 0
2 years ago
Consider the following code snippet: int count = 0; int[][] numarray = new int[2][3]; for (int i = 0; i < 3; i++) { for (int
inna [77]
I have never seen this in my life sorry
7 0
3 years ago
What is the output of the following function call? //function body int factorial(int n) { int product=0; while(n > 0) { produ
maks197457 [2]

Answer:

zero

Explanation:

Because of the define the product variable is zero.

when the function call with pass by value 4.

The program control moves to that function, after that product

store the value zero. Then, product is multiply with n which become zero

because 0 * n is zero and store in the product again.

after that, n'' is wrong it must be 'n--' for performing the factorial function.

after that, the value of n is 3, again loop execute because condition n > 0

is true.

again zero multiply with n and become zero.

this process repeated until condition false and finally the output is zero.

Correction:

To make the code working:

change product = 1 instead of zero.

and change n-- in place of n''.  

5 0
3 years ago
Other questions:
  • Is there a way to find the answers to I ready on the internet?
    6·1 answer
  • Written and artistic expressions are protected by
    8·1 answer
  • Nested if-else structures can contain many blocks of code. How many of those blocks of code might be executed?
    14·1 answer
  • Dayla is concerned about managing her digital footprint. What does she mean by this? *
    7·1 answer
  • You work in the Accounting department and have been using a network drive to post Excel workbook files to your file server as yo
    15·1 answer
  • Identify the electronic community that is a social-networking site.
    5·2 answers
  • You need to update both the DEPARTMENT_ID and LOCATION_ID columns in the EMPLOYEES table using one UPDATE statement. Which claus
    5·1 answer
  • Which of the displays could be represented by a single bit?
    12·2 answers
  • Which feature allows you to copy attributes of
    11·1 answer
  • 6
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!