1 given a file object named output associate it with a file


PYTHON PROGRAMMING:

1. Given a file object named output, associate it with a file named year summary.txt by opening the file for appending

2. Using the file object input, write code that read an integer from a file called rawdata into a variable  datum (make sure you assign an integer value to datum). Open the file at the beginning of your code, and close it at the end.

3. A file named numbers.txt contains an unknown number of lines, each consisting of a single positive integer. Write some code that reads through the file and stores the largest number read in a variable  named maxvalue.

4. A file named data1.txt contains an unknown number of lines, each consisting of a single integer. Write some code that creates a file named data2.txt and copies all the lines of data1.txt to data2.txt.
5. Two files named numbers1.txt and numbers2.txt both have an unknown number of lines, each line consisting of a single positive integer. Write some code that reads a line from one file and then a line from the other file. The two integers are multiplied together and their product is added to a variable  called scalar_product which should be initialized to zero.

Your code should stop when it detects end of file in either file that it is reading.

For example, if the sequence of integers in one file was "9 7 5 18 13 2 22 16" and "4 7 8 2" in the other file, your code would compute:

4*9 + 7*7 + 8*5 + 2*18

and thus store 161 into scalar_product.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: 1 given a file object named output associate it with a file
Reference No:- TGS02512052

Now Priced at $20 (50% Discount)

Recommended (90%)

Rated (4.3/5)