IN python 1Given four files named asiasales2009txt europesal

IN python

1.Given four files named asiasales2009.txt, europesales2009.txt, africasales2009.txt, and latinamericasales2009.txt, define four file objects named asia, europe, africa, and latin, and use them, respectively, to open the four files for writing.

2.Given a file object named output, associate it with a file named yearsummary.txt by opening the file for appending

3.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.

Solution

Program Code

def fileWriting():

    # task 1

    #for first file asiasales2009.txt for writing

    asia = open(\"E:/asiasales2009.txt\",\"w\");

    #for second file europesales2009.txt for writing

    europe = open(\"E:/europesales2009.txt\",\"w\")

    #for third file africasales2009.txt for writing

    africa = open(\"E:/africasales2009.txt\",\"w\")

    #task 2

    #for open file yearsummary.txt for appending

    yearsummary = open(\"E:/yearsummary.txt\",\"a\")

    #task 3

    #read an integer from a file called rawdata into a variable datum

    #file opened in read mode

    readData = open(\"E:/rawdata.txt\",\"r\")

   

    #read the lines from file

    lines = readData.readlines()

    #iterate the eachline from lines

    for eachline in lines:

       #find the type of each line

        #it is integer then store

        if(type(eachline) == \'int\'):

            print \"each line is integer\";

            #store into datum variable

            datum = eachline

         

#defination call here

fileWriting();

IN python 1.Given four files named asiasales2009.txt, europesales2009.txt, africasales2009.txt, and latinamericasales2009.txt, define four file objects named as
IN python 1.Given four files named asiasales2009.txt, europesales2009.txt, africasales2009.txt, and latinamericasales2009.txt, define four file objects named as

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site