# Reviews

  1. What type of file access jumps directly to any piece of data in a file without reading the data that came before it?

    • Sequential
    • Random
    • Number
    • Text
  2. Assume that the customer file references a file object, and the file was opened using the w mode specifier. How would you write the string Mary Smith to the file?

    • customer_file.write('Mary Smith')
    • customer.write('w','Mary Smith')
    • customer.input('Mary Smith')
    • customer.write('Mary Smith')
  3. What statement can be used to handle some of the run-time errors in a program?

    • exception statement
    • try statement
    • try/except statement
    • exception handler statement
  4. What statement below is a correct call to function func?

    def func(farg, **kwargs):
        print ("formal arg:", farg)
        for key in kwargs:
            print ("another keyword arg: %s: %s" %
                (key, kwargs[key]))
    • func('one','two', c='three',d='four')
    • func('one',c='three',d='four')
    • func(c='three',d='four')
    • func('one','two', 'three', 'four')
  5. Which of these is associated with a specific file and provides a way for the program to work with that file?

    • Filename
    • Extension
    • File object
    • File variable
  6. Which method will return an empty string when it has attempted to read beyond the end of a file?

    • read
    • getline
    • input
    • readline
  7. What will be displayed given the following function definition and function call?

    def divide(x, y):
        try:
            result = x / y
        except ZeroDivisionError:
            print ("division by zero!")
        else:
            print ("result is", result)
        finally:
            print ("executing finally clause")
    divide(2, 1)

    result is 2.0
    executing finally clause

  • Questions 8-9 refer to the following code.

    # Open a file
    fo = open("foo.txt", "w")
    fo.write( "Python is a great language.\nYeah its great!!\n");
    # Close opened file
    fo.close()
  1. What will be displayed given the code?

    # Open a file
    fo = open("foo.txt", "r+")
    str = fo.read();
    print ("Read String is : ", str)
    # Close opened file
    fo.close()

    Read String is : Python is a great language.
    Yeah its great!!

  2. What will be displayed given the code?

    # Open a file
    fo = open("foo.txt", "r+")
    str = fo.readline();
    print ("Read String is : ", str)
    # Close opened file
    fo.close()

    Read String is : Python is a great language.