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
Do the pros of interpersonal communication via social media outweigh the cons? Explain.
JulijaS [17]
Well in my opinion is that yes they do. The ability to be able to communicate with others so far way really helps society advance towards the future. And i cant stress of how the benefits of being able to share ideas with well anyone is so wonderful.

I hope this helps.
6 0
3 years ago
Read 2 more answers
What does it mean to prioritize tasks?
salantis [7]

Answer:

to rank tasks from most to least important

Explanation:

Prioritize means to choose priority, obviously and priority is the thing is the thing which, among other things, have the biggest importance.

Every day, especially in business, one finds himself swimming in tasks up to his neck. Obviously, not all of them can be successfully finished, or at least not without sacrificing one's personal life or sleep.

Prioritizing, therefore, serves as a helpful organising tool. After writing down all tasks that need to be done, a person should rank them by priority, which means that only urgent and important tasks will be dealt with immediately. Tasks of lower priority will be postponed, delegated or simply deleted.

6 0
2 years ago
Read 2 more answers
Your license can be canceled if you __________
Elena L [17]
Its B i think hope this helps ! 
8 0
3 years ago
Read 2 more answers
What are you required to verify before allowing a person to operate your pwc?
stich3 [128]

<span>Before allowing a person to operate PWC, check that they meet the minimum age and boater education requirements for PWC. While near shore, show how to start and re board the PWC properly and make sure that he has at least 25 hours of PWC operation experience. Be sure explain how to steer and control the PWC properly.</span>

8 0
3 years ago
In the function below, use a function from the random module to return a random integer between the given lower_bound and upper_
sladkih [1.3K]

Answer:

import random

def ran(lower_bound, upper_bound):

   return random.randrange(lower_bound, upper_bound)

print(ran(3, 8))

Explanation:

The programming language used is python.

Modules are imported using the import keyword. In the first line the random module is imported.

A function ran is defined and it has two parameters, lower and upper bound that wll be passed to the function from random module.

The random module is a module that is used to generate random numbers, it is a very common module in programming, some of the popular functions in the module are random.randint and random.randrange. There are several other functions but these are the most common. the randint(a, b) takes two arguments and returns a random integer between the two arguments.

randrange(start, stop, step); It can take up to three arguments but has only compulsory argument that must be given for it not to generate an error and that is the stop.

when only the stop is defined, it assumes the start as zero and creates a range from 0 - stop and returns a random number within that range.

When start and stop arguments are given, it returns a number within the range of start - stop.

Start and stop must be given for there to be a step, if the step is given, it means the array containing the range of numbers will skip a step after each number.

The program makes use of the random.randrange(start, stop) and the upper and lower bounds are passed as its arguments.

Finally, the function is called and its return value is printed to the screen.

6 0
3 years ago
Other questions:
  • How can i appear offline without fb messenger saying "last active 1 minute ago"?
    5·1 answer
  • Both the USB flash drive and the DVD are data storage devices, but they both have numerous differences. Both can contain insane
    6·1 answer
  • In a computerized accounting system, each transaction that is analyzed must be entered by hand into the appropriate journal and
    12·2 answers
  • Why would a designer choose to use an isometric sketch rather than a perspective sketch to share their idea with a design team m
    14·1 answer
  • Explain SATA peripheral bus operation?
    14·1 answer
  • How does the financial market impact the economy?
    10·1 answer
  • Describe two types of storage devices?​
    15·1 answer
  • Organizations following Waterfall methodology usually begin with requirements gathering, in which the development team attempts
    14·1 answer
  • Combination of one or more columns used to identify particular rows in a relation is a (n)<br>​
    8·1 answer
  • What kind is a utility file that shrinks the size of a file
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!