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
You have been given a laptop to use for work. You connect the laptop to your company network, use it from home, and use it while
VashaNatasha [74]
  • You can get a antivirus subscription that will kill malwares
  • Also, you can avoid going on websites you don't trust
  • I hope this helps you.
4 0
3 years ago
Select Packet 10 in the Wireshark top pane and then answer the following questions: Did this handshake complete properly? What i
Yuki888 [10]

Answer:

Yes

32 bytes

No

40 bytes

6 0
3 years ago
Write a function named average_value_in_file that accepts a file name as a parameter and reads that file, assumed to be full of
noname [10]

def average_value_in_file(filename):

   f = open(filename)

   total = 0

   count = 0

   for x in f.read().splitlines():

       total += int(x)

       count += 1

   return total/count

print(average_value_in_file("input.txt"))

I used an input file that looks like this:

1

1

1

1

6 0
3 years ago
kara, darrell and jose all enjoy watching comedies online. kara and jose also enjoy watching dramas. using content-based filteri
vitfil [10]

Answer:

thrillers?

Explanation:

my best estimation would most likely be a thriller...

4 0
3 years ago
Code in VMware Fusion?
ivanzaharov [21]
The answer to your problem is 76 because u have to multiply them u have to add them u have to divide but the original mumber
7 0
3 years ago
Other questions:
  • Clifford created a table using OpenOffice Writer and entered some information into the table. Later, he needed to add more rows
    15·2 answers
  • Mary is writing an article about the software development life cycle. She wants to place a flowchart besides the text. Which men
    6·2 answers
  • In Microsoft Word, spelling errors are identified by a _____.
    5·2 answers
  • Which of the following is an example of a federal tax? A. Social Security tax B. Sales tax C. Property tax D. Transaction tax
    8·1 answer
  • What are the seven internal compontents of a computer
    10·1 answer
  • An algorithm written out in plain English statements is called __________.
    8·1 answer
  • An example of creative curating is when a:
    9·1 answer
  • You are in the windows power shell window and decide to encrypt folder which of the following command do you use
    7·1 answer
  • Jessie will make and sell the trending Baked California Maki. Her Peso mark up is 5.00. Selling price PHP 15.000. How much will
    7·1 answer
  • Prompt
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!