Test 2

Date & Time

Wednesday, April 2, 12:30-1:45pm, PM 103

Overview

Test 2 will cover all material from the beginning of the semester through testing but with an emphasis on material covered since Test 1 (including system integration). This material includes everything discussed in lectures and covered in assignments, and aligns with chapters 1-6 and 8-10 from the recommended text. We have covered some additional topics the text has not, including OS Integration, and we did not cover the data science additions to each chapter. Because this is a programming principles course, there will be questions related to principles as well as questions that involve syntax. You may be asked to write, analyze, and/or debug code.

Format

  • Multiple Choice
  • Free Response

Example Types of Questions

  • Why are raw strings useful for regular expressions?
  • How would you check if a string contains only digits?
  • Which string operator gets rid of whitespace at the end of a string?
  • Which statement is a context manager associated with? Why is it useful when writing to files?
  • Why is it important to know which encoding a text file used?
  • Why would you use the statement if __name__ == "__main__" in a script?
  • What is the type of the entries in sys.argv? Suppose you are writing a script that takes two arguments and computes their sum; what may do you need to do before adding the arguments?
  • What is a wildcard import in Python? Why should you avoid them in general?
  • What is the difference between a Python module and a Python package?
  • Create an inheritance hierarchy from the following classes: Vehicle, Car, Truck, SportsCar, Sedan
  • Given a definition of the Vehicle class, write a constructor for the Car class that takes the number of doors as an argument and stores it.
  • Given a definition of a class, locate errors and detail fixes for them.
  • Given an instance obj which has initialized instance fields var1, _var2, and __var3, which reference does not work? obj.var, obj._var2, obj.__var3?
  • What is the difference between a class method and a static method?
  • What is duck typing?
  • When handling an exception, why is using a bare except clause problematic?
  • If you have two excception handlers, one for IOError and one for FileNotFoundError, which should be placed first? Why?
  • What are some problems with debugging using print statements or testing using assert statements?
  • When processing paths, how can you distinguish between files and directories?
  • Given a path of the form p = "/path/to/file.txt", how can you compute the output path "/output/path/file.json"?