answer.
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
sergij07 [2.7K]
2 years ago
3

Write a code segment that prompts the user for a filename. If the file exists, the program should print its contents on the term

inal. Otherwise, it should print an error message.
Computers and Technology
1 answer:
Sergio039 [100]2 years ago
7 0

Answer:

Code is written in Python

dataobject = DataTransferinFiles()

Should be just:

dataobject = DataTransferinFiles()

So the full code:

class DataTransferinFiles():

def transfer(self,firstfilename,secondfilename):

print("your first file is=",firstfilename);

print("your second file is =", secondfilename)

with open(firstfilename,'r')as filedata:

firstfiledata= filedata.readlines()

print()

print("1st file reading complete")

print()

with open(secondfilename, 'r')as filedata:

secondfiledata=filedata.readlines()

print("2st file reading complete")

for eachline in firstfiledata:

filesecond = open(secondfilename,'a')

filesecond.write("/n"+eachline+ "/n")

print ("1st file transfered in to second file")

for eachline in secondfiledata:

filefirst = open(firstfilename)

filefirst.write("\n"+eachline+ "\n")

print ("second file transfered in to first file")

dataobject = DataTransferinFiles()

firstfilename = input("enter first file name for transfer")

secondfilename = input("enter second file name for transfer")

dataobject.transfer(firstfilename,secondfilename)

You might be interested in
You are given an array x of string elements along with an int variable n that contains the number of elements in the array. You
Slav-nsk [51]

Answer:

The code to this question can be given as:

Code:

int i,j,count_previous=0,count_next=0; //define variable

for (j=0; j<n; j++) //loop for array

{

if (x[0]==x[j]) //check condition

{

count_previous++; //increment value by 1.

}

}

for (i=0; i<n; i++) //loop

{

for (j=0; j<n; j++)

{

if (x[i]==x[j]) //check condition

{

count_next++; //increment value by 1.

}

}

if (count_previous>count_next) //check condition

{

mode=x[i-1];

}

else

{

mode=x[i];

count_previous=count_next; //change value.

count_next= 0 ; //assign value.

}

}

Explanation:

In the question it is define that x is array of the string elements that is already define in the question so the code for perform operation in the array is given above. In the code firstly we define the variable that is i, j, count_previous, count_next. The variable i,j is used in the loop and variable count_previous and count_next we assign value 0 that is used for check the values of array. Then we define the for loop in this loop we use conditional statement in the if block we check that array of zero element is equal to array of j value then the count_previous is increase by 1. Then we use nested loop It is also known as loop in a loop. In this first loop is used for array and the second loop is used for check array element.In this we use the condition that if array x of i value is equal to array x of j then count_next will increment by 1.Then we use another condition that is if count_previous is greater then count_next then mode of x is decrement by 1. else mode equal to array and count_previous holds the value of count_next and count_next is equal to 0.

8 0
2 years ago
Write a function named printtriangle that receives a parameter that holds a non-negative integer value and prints a triangle of
NemiM [27]
Static void PrintTriangle(int n){    for(;n>0;n--) {                Console.WriteLine(new String('*', n));    }}
5 0
2 years ago
Which is true for a hosted blog software
professor190 [17]
Since you have not provided the choices wherein I will have to choose from to arrive at an answer, I will just explain to you the concept revolving around a hosted blog software. Hosted blog software are basically installed by the owner of the web server in which among its famous platforms is the Blogger.
7 0
2 years ago
Read 2 more answers
Which of the following word pairs correctly completes the sentence below?
Julli [10]

B. negative, positive

4 0
2 years ago
Read 2 more answers
What is the data transmission time, assuming no errors or overhead, to send a 2 GByte file over a link with a 2 Gbps line rate?
schepotkina [342]

Answer:

The data transmission time will be 8 seconds (8.0s)

Explanation:

Using the formular:

T =A/S

T=Time = ?

Amount of Data = A = 2GByte

Speed = S = 2Gbps

The units of A and S are different

A is expressed in Bytes(B)

S is expressed in bits(b)

But :

1 Byte(B) = 8 bits(b)

T = A/S = 2GB/2Gb

since 1 Byte = 8 bits

T = 2 × G ×( B =8bits) / 2 × G × b

T = 2 × G × 8b / 2 × G × b

T = 2 × G × 8 × b / 2 × G × b

The common terms(2,G,b) cancel out

T = 8 seconds

4 0
2 years ago
Other questions:
  • Mr. Cooper would like to customize his Excel software so his students can create an electronic graph in Excel for their lab repo
    6·1 answer
  • Which word in brackets is most opposite to the word in capitals? PROSCRIBE (allow, stifle, promote, verify)​
    14·2 answers
  • Which is the term for a computer typically located in an area with limited security and loaded with software and data files that
    9·1 answer
  • When configuring a record type, an App Builder can configure the available value of a picklist field for the page layout. Which
    9·1 answer
  • You decide to buy some stocks for a certain price and then sell them at anotherprice. Write a program that determines whether or
    11·1 answer
  • A few of your employees have complained that their computers sometimes shut down spontaneously. You have noticed that these empl
    6·1 answer
  • C++
    8·1 answer
  • In Java please.
    12·1 answer
  • Write a program that has the following String variables: firstName, middleName, and lastName. Initialize these with your first,
    7·1 answer
  • Ali has created a small program in Python, but he wants to store his data in a multi-dimensional array. He would like to use adv
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!