- Fill in the blank: [25]
- "Computers are tools__________, and computing scientists
are toolsmiths________________."
- The software development model that emphasizes repeated iterations
through the waterfall (WADES) process, with refinements each time, is called
spiral or agile____________.
- In software development, the document that describes the functionality
you intend to deliver to the client is called the
specifications________________.
- Testing of a single component in isolation (as opposed to integration
testing) is called unit________ testing.
- 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.
- What word describes functions which invoke themselves?
recursion________
- The Python keyword used to introduce an exception handler clause is
except__________
- When an object is printed, Python invokes the object method
named __str__()_______________.
- Convert 1010011110 from binary to hexadecimal: 0x29E_______
- Convert the same to octal: 01236_______
- Evaluate: range(5,5): [] (empty list)____________
- What is the type of the Python expression
2*'x' + 'y' ? string________
- In Python classes, the __init__() method is the special
method called the constructor or initializer____________________.
- Name three drawable objects in Zelle's graphics.py library.
Point, Line, Circle, Rectangle, Oval, Polgyon
__________ __________ __________
- What method returns a list of all the indices in a dictionary?
keys()________
- The Python method on file objects that sets the file pointer
(location within the file) is called seek()__________
- The function in the standard library string which transforms
all letters within a string to uppercase is called upper()_________
- What English part of speech should a variable name be?
noun___________
- What operator is used to indicate bitwise left shift?
<<_______
- (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_____________
-
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
___________ |
___________ |
___________ |
___________ |
___________ |
-
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.
-
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
___________ |
___________ |
___________ |
___________ |
___________ |
-
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
- 0x2b 43
- 14 & 7 6
- 17040183 % 2 1
- [2, 4, 6] * 2 [2, 4, 6, 2, 4, 6]
- [2, 4, 6] + 8 TypeError: list + int
- "03d%s" % (15, 'pears') TypeError (# args)
- 'b' in myPear False
- string.upper(Bartlett) NameError: Bartlett
- range(myPear) TypeError
- myPear[2:6] 'd Ba'
- sorted(myPear) ' BRadeelrtt' (as a list, actually)
- chr(ord('P') + 4) 'T'
- 'pi' + 'e' 'pie'
- 'pie' - 'e' TypeError: str - str
- pi + 'e' TypeError: float + str
-
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.)
-
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.
-
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
-
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.
-
Consider the following Python expression:
5 + 2 ** 4 % 10 < 43 / 4 or not 3 in range(0, 10, 2)
- 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()'.)
- 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]
-
Define or describe each of the following object-oriented terms:
[7]
- Class: a user-defined container type
- Instance: an object; instances are to classes as variables are to
types
- Attribute: a variable or method belonging to an object
- Method: a function/procedure belonging to an object
- Constructor/initializer: the special method which is called when an object is
instantiated
- Interface: a set of messages that an object can receive
- Overloading: giving multiple definitions to a
function/method/operator depending on the type of its parameters/operands
-
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.
-
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.
-
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.
-
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.
-
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:
2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | 11 | 12 |
Snake Eyes | Ace Deuce | Easy Four (2+2 = Hard Four) |
Fever Five | Easy Six (3+3 = Hard Six) | Natural |
Easy Eight | Nina | Easy Ten | Yo | Boxcars |
See separate Python code.