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
Complete the function to return the result of the conversiondef convert_distance(miles):km = miles * 1.6 # approximately 1.6 km
AnnZ [28]

Answer:

The complete program is as follows:

def convert_distance(miles):

   km = miles * 1.6 # approximately 1.6 km in 1 mile

   return km

my_trip_miles = 55

# 2) Convert my_trip_miles to kilometers by calling the function above

my_trip_km =convert_distance(my_trip_miles) #3) Fill in the blank to print the result of the conversion

# 4) Calculate the round-trip in kilometers by doubling the result,

print("The distance in kilometers is " +str(my_trip_km))

# and fill in the blank to print the result

print("The round-trip in kilometers is " + str(my_trip_km * 2))

Explanation:

<em>The program is self-explanatory because I used the same comments in the original question.</em>

5 0
2 years ago
If the value of score1 is 350 and the value of score2 is 210, what will be the value of result after the code segment is execute
MAVERICK [17]

  The value of result of the  code segment is executed is known to be 4.

<h3>Why is the value of the code segment so?</h3>

  When the result of  is not  executed because the condition is said to be false and also when there is a false condition is, the else statement will be said to be true

  Therefore,   result = result + 2; -> result is brought up by 2 to bring about 4 and as such, the value of result of the  code segment is executed is known to be 4.

Learn more about scores from

brainly.com/question/19492935

#SJ1

4 0
2 years ago
What are the advantages and disadvantages of using wireless communications? What are the advantages and disadvantages of using w
Nimfa-mama [501]

Answer:

<u>Advantages of wireless communication:-</u>

  • Flexibility in transferring the message through communication for which the sender and receiver can be in any place.
  • Speed of the communication is accurate and fast
  • Due to no wiring , the cost of the wireless communication is less.

<u>Disadvantages of wireless communication:-</u>

  • The security is less as the data can be accessed by unauthorized sources at times.
  • The setting up of wireless communication complex and expensive.

<u>Advantages of wired communication:-</u>

  • Simple configuration
  • Higher bandwidth is present in the cable
  • High reliability

<u>Disadvantages of wired communication:-</u>

  • Mobility is present for communication
  • Installation requires lot of time due to cabling
  • Requires extra devices for covering large areas for communication

Wireless communication is more preferable than wired communication in the conditions like communication connection that should face low damage and longer life which is not present in cable connection as they break or get disrupted.The flexibility of moving while communication is required by most people so, they use wireless communication .

8 0
3 years ago
In computer science, what are two names that are used to describe data structures organized by association
Bas_tet [7]

Answer:

Answer to the following question are,

  • Association list
  • Tables

Explanation:

Because these are the two associations data structures.

  • Association List: are referred to that data type which contains the pair of the key and item in the Java Programming Language and Python Programming Language, it is called a dictionary data type.
  • Tables or Hash Tables: are referred to that data type which converts the keys into the integer value.
6 0
3 years ago
How can I put my keyboard back​
zvonat [6]

Flip the laptop over, take off the screws that hold the frame together. Flip it back, take off the top plate. Then, slide the keyboard back in. Replace the frame, and then rescrew the screws. Replace the back side after.

~

8 0
3 years ago
Other questions:
  • Default tab stops are set in Word every _______ inch.<br> a. ¾<br> b. 1<br> c. ½<br> d. ¼
    13·1 answer
  • The Caesar Cipher has 25 different shifts to try.
    14·1 answer
  • Point mode allows you to select cells for use in a formula by using your finger or the pointer
    7·1 answer
  • Daniel makes changes to a workbook named “Results.” He saves the file as “New Results” but did not realize that a worksheet name
    10·1 answer
  • which software is used to mimic intricate hand drawings into digital paintings? _____ is used to replicate hand drawings into di
    7·1 answer
  • • In your response, please include some examples of the three different types of storage.
    11·2 answers
  • Write four overloaded methods called randomize. Each method will return a random number based on the parameters that it receives
    5·2 answers
  • Do you think LinkedIn stands to change the way employers hire? If so, how? Would this be a positive change or a negative one? Ex
    14·1 answer
  • Which of the following are input devices? Check all that apply.
    9·2 answers
  • Which programming paradigm does the programming language JavaScript follow?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!