Exam 2

advertisement
Computer Science 101
Survey of Computer Science
Exam 2 Fall, 2010
Name:
Pledged:
1. (25 points) Complete the following:
a. In Python, assume that we have already executed the statement
scores = [85,90,75,80,94,65,84]
Give the value of len(scores):
Give the value of scores[3]:
b. Assuming that we are using the random library of Python, circle the ones of the
following that would not be possible values obtained from randrange(10,20):
5
10
15
20
25
c. What would be printed if we executed the statement
print range(3,7)
in Python?
d. What is the largest number that we can express using 5-bit unsigned numbers?
Give answer in decimal:
e. What is the largest positive number that we can express using 5-bit 2’s
complement numbers? Give answer in decimal:
f. Here Log indicates logarithm to base 10.
Log (10,000) =
g. Here Lg indicates logarithm to base 2.
Lg (512) =
h. If the decibel level of a sound wave increases by 20 decibels, then the actual
pressure is multiplied by
.
i. The
of a sound wave is the number of cycles per
second. This determines the pitch of the sound – how high or how low the sound
seems to us.
j. One type of redundancy that can be exploited in attempting to compress a picture
. Explain what this means:
2. (5 points) In Python, assume that we have already executed the statement
scores = [85,90,75,80,94,65,84]
Using a loop (either a while-loop or a for-loop), write a section of Python code that
would add 5 to each of the values in the list scores.
3. (20 points) Perform the following conversions.
a. Express the decimal number 156 as a 10-bit 2’s complement number.
b. Express the decimal number -156 as a 10-bit 2’s complement number.
c. Express the 5-bit 2’s complement number 01110 as a decimal number.
d. Express the 5-bit 2’s complement number 10010 as a decimal number.
4. (25 points) Assume that, in JES, we have successfully executed the command
myPicture = makePicture(“FallColonnade.jpg”)
For each of the following, write one or more statements to achieve the task. Parts a.
through d. refer to the picture object called myPicture.
a. Print out the red component of the pixel at location (32, 200).
b. Change the red component of the pixel at (32, 200) to be 0, leaving the green and
blue components alone.
c. Print out the red component of the pixel in the upper left corner of the picture.
d. Print out the red component of the pixel in the upper right corner of the picture.
e. Complete the code for the following function:
# This function sets the value of the red component of all of the pixels of
#
thePicture to zero, leaving the green and blue values unchanged.
def zeroRed(thePicture) :
5. (25 points) Assume that, in JES, we have executed the command
mySound = makeSound(“preamble.wav”)
For each of the following, write one or more statements to achieve the task. The parts
a. through d. refer to the sound object called mySound.
a. Print out the sample value of the first sample in mySound.
b. Set the first sample value of mySound to be 0.
c. Set the last sample value of mySound to be 0.
d. Set all sample values of mySound to be 0.
e. Complete the code for the following function:
# This function sets the value of all samples of theSound in the section starting at
#
location phraseBegin and ending at location phraseEnd to 0. The other
#
samples are left unchanged.
def erasePhrase(theSound, phraseBegin, phraseEnd) :
Download