-
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]
___________ |
___________ |
___________ |
___________ |
___________ |
- Fill in the blank: [22]
- "Computers are t________s, and computing scientists are t___________s."
- How many bits are in a nibble? __________
- 1011 0110 shifted two right, in binary, is ____________________
- Convert 0x1BE to decimal: _____________
- Convert 1100 0110 from binary to octal: _______________
- What word describes functions which invoke themselves? ___________
- The Python command used to trigger a user-defined exception is
________________ .
- True or False (circle one): The word Apples_For_Dr.Ho
is a legal Python identifier.
- What is the type of the Python expression 5**2 ? _________
- What Python command is used to convert an integer into a real value?
__________
- Name the two optional reserved words used in the Python program control
construct which corresponds to selection: _____________ ________________
- The first assignment of a value to a variable is called
________________ it.
- 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. _______________________
- The standard Python function which produces a pseudorandom real number
between 0 and 1 is in the
_______________ standard library and is named _______________ .
- The Python function which counts the number of characters in a string
is named _____________ .
- What English part of speech should a function name be? ___________
- What symbol is used to separate statements in a sequence in C or M2?
______
- What symbol is used to indicate logical negation in Python? ______
- 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 _______________________ .
-
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]
-
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
- 'pi' + 2*'z' + 'a'
- 2 + 1>4 and (5/0 < 1)
- 2.0 + 14 / 4
- 6 ^ 5
- "%03d%s" % (15.189, 'pears')
- string.upper(DAnjou)
- "%05.2f" % 2.7182818
- '%.2f' % (19 % 5)
- range(myPear)
- myPear[1:4]
- 'd' + 'b'
- ord('d') - ord('b')
- 'd' - 'b'
- 'b' + 3 == 'd'
-
What is a namespace? Tell me everything you know about scope rules and
namespaces in Python.
[5]
-
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.
- Consider the intersection of myFav and yrFav.
Express in words the interpretation of this intersection
in the context of apple preferences. [2]
- Consider the set difference yrFav - myFav.
Express in words the interpretation of this set difference
in the context of apple preferences. [2]
- 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]
- Using the variables you just defined, define a Python bitset
for yrFav. [2]
- Write a Python expression for the intersection of
myFav and yrFav. [2]
-
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
-
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);
-
Define or describe each of the following object-oriented terms:
[7]
- Class
- Instance
- Attribute
- Method
- Constructor
- Interface
- Overloading
-
Modula-2 and C have no built-in string type. What is a string
in Modula-2 or C?
[3]
-
Describe all the differences between Python lists and C arrays.
[4]
-
Explain all the differences between atomic and
aggregate/compound/container data types. Give examples of each.
[4]
-
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]
-
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]
-
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]