Name: __________________
Student ID: __________________

Total points: 115
  1. Name the five steps to top-down
    problem solving as described in the text.
    (It's okay if you can't remember the exact wording; the concepts are more important.) [5]

    ___________ ___________ ___________ ___________ ___________
  2. Fill in the blank: [22]
    1. "Computers are t________s, and computing scientists are t___________s."
    2. How many bits are in a nibble? __________
    3. 1011 0110 shifted two right, in binary, is ____________________
    4. Convert 0x1BE to decimal: _____________
    5. Convert 1100 0110 from binary to octal: _______________
    6. What word describes functions which invoke themselves? ___________
    7. The Python command used to trigger a user-defined exception is ________________ .
    8. True or False (circle one): The word Apples_For_Dr.Ho is a legal Python identifier.
    9. What is the type of the Python expression 5**2 ? _________
    10. What Python command is used to convert an integer into a real value? __________
    11. Name the two optional reserved words used in the Python program control construct which corresponds to selection: _____________ ________________
    12. The first assignment of a value to a variable is called ________________ it.
    13. A cable modem connection runs at 4Mb/s. Assuming full utilization of the bandwidth (which never happens in reality), how long would it take to download a 2GB file? Use binary units. _______________________
    14. The standard Python function which produces a pseudorandom real number between 0 and 1 is in the
      _______________ standard library and is named _______________ .
    15. The Python function which counts the number of characters in a string is named _____________ .
    16. What English part of speech should a function name be? ___________
    17. What symbol is used to separate statements in a sequence in C or M2? ______
    18. What symbol is used to indicate logical negation in Python? ______
    19. A requirement imposed by a function upon its parameters, such that the correctness of the result is not guaranteed if the requirement is not met, is called a _______________________ .
  3. Name the five computer program flow abstractions described in the text, and for the four which we covered in class, show how each is done in Python. [9]







  4. Evaluate each of the following Python expressions exactly as given, or if it produces an error, describe the error. Assume each expression is independent of the others. Assume all necessary imports have been done. For all expressions, assume the following initialization: [14]
    	myPear = "DAnjou"
    	from math import pi	
    1. 'pi' + 2*'z' + 'a'
    2. 2 + 1>4 and (5/0 < 1)
    3. 2.0 + 14 / 4
    4. 6 ^ 5
    5. "%03d%s" % (15.189, 'pears')
    6. string.upper(DAnjou)
    7. "%05.2f" % 2.7182818
    8. '%.2f' % (19 % 5)
    9. range(myPear)
    10. myPear[1:4]
    11. 'd' + 'b'
    12. ord('d') - ord('b')
    13. 'd' - 'b'
    14. 'b' + 3 == 'd'

  5. What is a namespace? Tell me everything you know about scope rules and namespaces in Python. [5]






  6. An orchard grows five apple varieties:
    Fuji, Gala, Spartan, Rome, and Melba.
    The apples I like are Fuji, Gala, and Rome; let this set be denoted by myFav.
    Let yrFav be the set containing Fuji and Melba.
    1. Consider the intersection of myFav and yrFav. Express in words the interpretation of this intersection in the context of apple preferences. [2]



    2. Consider the set difference yrFav - myFav. Express in words the interpretation of this set difference in the context of apple preferences. [2]



    3. We wish to implement some set operations using bitsets in Python. Define five Python variables Fuji, Gala, Spartan, Rome, Melba with appropriate integer values for use in a bitset. [2]





    4. Using the variables you just defined, define a Python bitset for yrFav. [2]



    5. Write a Python expression for the intersection of myFav and yrFav. [2]


  7. What is wrong with the following Python loop? Rewrite it from scratch in a better way. [4]
    counter = 0
    sum = 0.0
    numitems = 0
    while counter < len(mylist):
    	sum = sum + mylist[counter]
    	numitems = numitems + 1
    average = sum / numitems
    
  8. The following Python function has at least eleven errors. Find and fix all of them. Points will be deducted for "fixing" what are not errors. [6]
    define round(float):
    	
    	""Round a float to the nearest integer (up or down)."""
    	
    	addhalf := (float++ 0 5)	// add 0.5 to float
    	
    	Return integer((addhalf);
    



  9. Define or describe each of the following object-oriented terms: [7]
    1. Class



    2. Instance



    3. Attribute



    4. Method



    5. Constructor



    6. Interface



    7. Overloading



  10. Modula-2 and C have no built-in string type. What is a string in Modula-2 or C? [3]


  11. Describe all the differences between Python lists and C arrays. [4]






  12. Explain all the differences between atomic and aggregate/compound/container data types. Give examples of each. [4]




  13. The file 'input.txt' contains a list of real numbers, one per line. Write a Python program to read in the numbers from the file and print their average to the screen. Docstring is required; pseudocode is not. [6]








  14. A certain sequence is defined by t1=0, t2=3, and after that ti=ti-1 + 2 ti-2, so that the first few terms of the sequence are 0, 3, 3, 9, 15, 33, 63, ....

    On a separate paper, write a recursive Python function to compute the nth term of this sequence. Docstring and preconditions are required; pseudocode is not (but may be good for partial credit). [8]




  15. A dynamic system that is being accelerated at a constant acceleration a has its initial velocity u, final velocity v, and the distance travelled d related by the formula
    v2 - u2 = 2ad.

    On a separate paper, write an interactive Python program that can calculate either d or a in terms of the others. Use at least one function. Docstrings are required for the program and all functions. Pseudocode is not required (but may be good for partial credit). [8]