[ answers in web view ]
Name: _______________________________ K E Y
Student ID: _______________________________

Unless otherwise specified, all questions pertain to Python.
Total points: 110
  1. Fill in the blank: [25]
    1. "Computers are tools__________, and computing scientists are toolsmiths________________."
    2. The software development model that emphasizes repeated iterations through the waterfall (WADES) process, with refinements each time, is called spiral or agile____________.
    3. In software development, the document that describes the functionality you intend to deliver to the client is called the specifications________________.
    4. Testing of a single component in isolation (as opposed to integration testing) is called unit________ testing.
    5. In statically-typed languages, before we can use the value of a variable for the first time in
      a program, we need to ______________declare and ________________initialize it.
    6. What word describes functions which invoke themselves? recursion________
    7. The Python keyword used to introduce an exception handler clause is except__________
    8. When an object is printed, Python invokes the object method named __str__()_______________.
    9. Convert 1010011110 from binary to hexadecimal: 0x29E_______
    10. Convert the same to octal: 01236_______
    11. Evaluate: range(5,5): [] (empty list)____________
    12. What is the type of the Python expression 2*'x' + 'y' ? string________
    13. In Python classes, the __init__() method is the special method called the constructor or initializer____________________.
    14. Name three drawable objects in Zelle's graphics.py library. Point, Line, Circle, Rectangle, Oval, Polgyon __________ __________ __________
    15. What method returns a list of all the indices in a dictionary? keys()________
    16. The Python method on file objects that sets the file pointer (location within the file) is called seek()__________
    17. The function in the standard library string which transforms all letters within a string to uppercase is called upper()_________
    18. What English part of speech should a variable name be? noun___________
    19. What operator is used to indicate bitwise left shift? <<_______
    20. (2pts) An Iridium satellite internet connection runs at 28 kb/s (kibibits/sec). Assuming full utilization of the bandwidth (which never happens in reality), how long would it take to download a 7 MB (mebibyte) document? Assume binary units. 2**11 == 2048 seconds, or 34 mins 8 seconds_____________
  2. Name the five steps to top-down problem solving as we discussed in class. (It's okay if you can't remember the exact wording; the concepts are more important.) [3]

    Write, Apprehend, Design, Execute, Scrutinize
    ___________ ___________ ___________ ___________ ___________
  3. Discuss the limitations of the software development model used in the previous question, and describe at least two alternate models that we talked about in class that might better reflect real-world software development. [6]
    Waterfall (WADES) assumes perfect requirements, perfect specification, perfect design, etc. In reality, we never get that, and have to move on with imperfect documentation, often resulting in a poor product and an unhappy client. The "V" model is a slight modification of WADES that emphasizes testing of each stage (components, systems, releases, products) before completion. The spiral model emphasizes repeated cycles of the waterfall model, early prototypes to get client feedback, and flexibility to changes in requirements, specification, or design.









  4. Describe the five software control/flow abstractions mentioned in the text. For each one, also name a corresponding Python language construct. [5]

    Sequence (newlines in Python), Selection (if/elif/else), Repetition (while/for), Composition (def/functions), Parallelism
    ___________ ___________ ___________ ___________ ___________


  5. Evaluate each of the following Python expressions exactly as given. If it produces an error/exception, describe the error in words. Assume each expression is independent of the others. For all expressions, assume only the following initialization: [15]
    	myPear = "Red Bartlett"
    	import string
    	from math import pi	
    1. 0x2b 43
    2. 14 & 7 6
    3. 17040183 % 2 1
    4. [2, 4, 6] * 2 [2, 4, 6, 2, 4, 6]
    5. [2, 4, 6] + 8 TypeError: list + int
    6. "03d%s" % (15, 'pears') TypeError (# args)
    7. 'b' in myPear False
    8. string.upper(Bartlett) NameError: Bartlett
    9. range(myPear) TypeError
    10. myPear[2:6] 'd Ba'
    11. sorted(myPear) ' BRadeelrtt' (as a list, actually)
    12. chr(ord('P') + 4) 'T'
    13. 'pi' + 'e' 'pie'
    14. 'pie' - 'e' TypeError: str - str
    15. pi + 'e' TypeError: float + str

  6. Is 3.6 in Python equal to the mathematical number 3.6? Explain why or why not. [3]
    Nope! (Try it!) Floating-point numbers are represented with limited precision. To represent 3.6 in binary requires an infinite number of bits, so the computer stores only an approximation to 3.6. (This is true of any computer language; it's not Python's fault.)


  7. What does the Python standard library 'pickle' do? [3]
    Object serialization: converts any Python object into a string representation, optionally storing it into a file. also converts back from string.




  8. Compare and contrast static typing versus dynamic typing. What are pros/cons of each? [4]
    (The key here is type: not whether the values of the variables can change, but whether their types can change.) Static typing: variables cannot change type Must declare type of variable and initialize value Compiler enforces correct type Dynamic typing: can change type More flexible, but usually we don't want variables to change type






  9. Describe all the differences between Python lists and C arrays. [4]
    Python lists can change length (can insert/delete), can have items of differing type, can have items which change type (due to Python's dynamic typing), and have various operators/functions defined on them, such as del, len(), negative indexing, list slicing, etc.









  10. Consider the following Python expression:
    5 + 2 ** 4 % 10 < 43 / 4 or not 3 in range(0, 10, 2)
    1. Rewrite the expression in Reverse Polish Notation. (This will not be valid Python code.)[3]
      5 2 4 ** 10 % + 43 4 / < 3 range(0, 10, 2) in not or
      (You could also split 'range(0,10,2)' further into '0 10 2 range()'.)


    2. Now evaluate your RPN expression, showing the state of the stack at each step. (If you show each step, partial credit will be given if you make a mistake at one point.) [4]
      [5], [5, 2], [5, 2, 4], [5, 16], [5, 16, 10], [5, 6], [11], [11, 43], [11, 43, 4], [11, 10], [False], [False, 3], [False, 3, range(0,10,2)], [False, False], [False, True], [True]



  11. Define or describe each of the following object-oriented terms: [7]
    1. Class: a user-defined container type
    2. Instance: an object; instances are to classes as variables are to types
    3. Attribute: a variable or method belonging to an object
    4. Method: a function/procedure belonging to an object
    5. Constructor/initializer: the special method which is called when an object is instantiated
    6. Interface: a set of messages that an object can receive
    7. Overloading: giving multiple definitions to a function/method/operator depending on the type of its parameters/operands




  12. What is the difference between the public interface and the private implementation of a library? Why should there be a distinction? Describe a specific example where the distinction would be helpful. [4]
    The public interface describes everything outside code needs to use the library: what the public classes and methods are, how to invoke the functions, etc. The private implementation is the code that makes the library work. Keeping them separate allows us to modify/upgrade the internal workings of the library without forcing other code using the library to change how it accesses the library. The public interface is the API; we want it to be stable.
  13. We wish to demonstrate the differences between alias, shallow copy, and deep copy. Come up with your own situation using user-defined classes that might illustrate this. Define the classes in Python, create an instance, then create an alias, a shallow copy, and a deep copy. The classes should make some sense! [6]
    See separate Python code.
  14. Tell me everything you know about exceptions in Python. [4]
    Exceptions are a way of breaking out of the normal flow of execution in a Python program. Exceptions are raised/thrown by built-in and standard library functions when errors happen. Exceptions may also be raised programmatically via the raise command. A try keyword delimits a block wherein an exception is expected to be raised. If an exception is raised anywhere within that try block, control jumps to the corresponding except block (the exception handler). The except clause may catch all exceptions (discouraged), or it may specify which exceptions it will handle. Any unhandled exceptions will continue looking for a handler down the call stack. The programmer may also define custom exceptions by subclassing the built-in class Exception.
  15. Describe in detail at least three principles of graphical user interface design. For each principle, describe or sketch an example UI that might violate that principle. [8]
    We covered many: know your users, be consistent with names/colours/etc., use metaphors carefully, use multiple levels of complexity (safety vs. control), always show current state, design around the epicentre, be tolerant of user mistakes, etc.
  16. The game of 'craps' uses two six-sided dice. The value of each roll is the sum of the values on each die; hence each roll can have a value between 2 and 12. Write a program that rolls a pair of dice 1000 times and outputs how many times each value is obtained. E.g., the value 2 ("snake eyes") turned up 28 times, 3 ("ace deuce") turned up 56 times, etc. [6]

    Docstrings are required for your program; comments are not required but may be helpful for partial credit if your code isn't perfect.

    FYI (just for fun), here are the names for each value of roll:

    See separate Python code.
    2 3 4 5 6 7 8 9101112
    Snake EyesAce DeuceEasy Four (2+2 = Hard Four) Fever FiveEasy Six (3+3 = Hard Six)Natural Easy EightNinaEasy TenYoBoxcars