Question

Here are the entire contents of the file 'test.txt': one two three What will the contents...

Here are the entire contents of the file 'test.txt':

one
two
three


What will the contents of 'test.txt' be after these statements are executed?

outfile = open('test.txt', 'a')
outfile.write('apple\n')
outfile.write('banana\n')
outfile.close()

The file will be empty.
apple
banana
applebanana
one
two
three
apple
banana
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:-

one
two
three
apple
banana

Explanation:- Here file is opening in append mode (a), so it write the content below the file data.

Add a comment
Know the answer?
Add Answer to:
Here are the entire contents of the file 'test.txt': one two three What will the contents...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Select the correct answer. (1)     Which of the following will open a file named MyFile.txt and...

    Select the correct answer. (1)     Which of the following will open a file named MyFile.txt and allow you to read data from it?                (a)      File file = new File("MyFile.txt");           (b)      FileWriter inputFile = new FileWriter();           (c)       File file = new File("MyFile.txt");                      FileReader inputFile = new FileReader(file);           (d)      FileWriter inputFile = new FileWriter("MyFile.txt"); (2)     How many times will the following do - while loop be executed?                      int x = 11;             do {             x...

  • Theres an error on The bolded line, what am I doing wrong? #include <iostream> //just for...

    Theres an error on The bolded line, what am I doing wrong? #include <iostream> //just for writing and reading from console #include <fstream> //this one to deal with files, read and write to text files using namespace std; int main() { //first thing we need to read the data in the text file //let's assume we have the reading in a text file called data.txt //so, we need a stream input variable to hold this data ifstream infile; //now we...

  • To insure that file output is written to the disk you need to execute what method?...

    To insure that file output is written to the disk you need to execute what method? a. commit() b. write() c. close() d. complete() The following is called the ________ of a function. def myFunction(x,y) : a. header b. footer c. sentinel d. index True or False: A commonly used program that uses regular expressions is grep. True or False: In Python exception handling provides a mechanism for passing control from the point of the error detection to a handler...

  • Instructions We have two states: Apple State and Banana State. There are three homogeneous goods, one...

    Instructions We have two states: Apple State and Banana State. There are three homogeneous goods, one factor input (labor), and unit labor requirements are given in the following table. We assume that wage rate in Apple State is $3 and that in Banana State is $4. Two states agree to trade goods freely. Answer the following two questions Units of labor required per unit of output Apple State Banana State Textile 4 1 Fish 3 2 Soybean 2 3 QUESTION...

  • 4. [10 marks] There are three bags one of which contains gold and the other two...

    4. [10 marks] There are three bags one of which contains gold and the other two are empty. Each bag has imprinted on it a clue as to its contents, the clues are: Bag 1 "The gold is not here" Bag 2 "The gold is not here" Bag 3 "The gold is in Bag 2" Only one message is true; the other two are false. Which bag has the gold? Formalize the puzzle in Propositional Logic and find the solution...

  • c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments:...

    c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of a file, a pointer to an int array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to the file, and then close the file. Write another function named fileToArray. This function should accept three argu- ments: the name of a file, a pointer to an int array, and the size...

  • 5. (40pts) Answer the following 3 questions about the file outFile. with open("outFile . txt", "**)...

    5. (40pts) Answer the following 3 questions about the file outFile. with open("outFile . txt", "**) as fh: aStr What does "w mean? "xy" while len(astr) < 6: fh.write(aStr+"n") aStr astr 2 When will the file output.txt be closed? Show what outFile.bxt will look like after the code has run: 6. (50pts) Given the following code segment, answer the 4 questions about the code. [21, 4, 15, 56, 8) nums N-e for number in nums: How many times does the...

  • Step 1: Getting Started Create a new .java file named Lab12.java. At the beginning of this...

    Step 1: Getting Started Create a new .java file named Lab12.java. At the beginning of this file, include your assignment documentation code block. After the documentation block, you will need several import statements. import java.util.Scanner; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; Next, declare the Lab12 class and define the main function. public class Lab12 { public static void main (String [] args) { Step 2: Declaring Variables For this section of the lab, you will need to declare...

  • 2. Write a function file_copy() that takes two string parameters: in file and out_file and copies...

    2. Write a function file_copy() that takes two string parameters: in file and out_file and copies the contents of in_file into out file. Assume that in_file exists before file_copy is called. For example, the following would be correct input and output. 1 >>> file_copy( created equal.txt', 'copy.txt) 2 >>> open fopen ( copy.txt') 3 >>> equal-f = open( 'created-equal . txt') 4 >>equal_f.read () 5 'We hold these truths to be self-evident, Inthat all men are created equalIn' 3. Write:...

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT