Study Guides (390,000)
CA (150,000)
UTSC (10,000)
All (20)
Midterm

CSCA08H3 Study Guide - Midterm Guide: Newline, Sound Module, Standard StreamsExam


Department
Computer Science
Course Code
CSCA08H3
Professor
All
Study Guide
Midterm

This preview shows pages 1-3. to view the full 10 pages of the document.
CSC A08H F 2011 Midterm Test
Duration — 100 minutes
Aids allowed: none
Student Number:
Last Name: First Name:
Lecture Section (circle one): L01 (afternoon) L02 (morning)
Do not turn this page until you have received the signal to start.
(Please fill out the identification section above, write your name on the back
of the test, and read the instructions below.)
Good Luck!
This midterm consists of 5 questions on 10 pages (including this one).
When you receive the signal to start, please make sure that your copy is
complete.
At the end of the test is a page to be used for rough work, and a page
containing functions and methods that may be of use to you. If you use any
space for rough work, indicate clearly what you want marked.
Comments are not required except where indicated, although they may help
us mark your answers. They may also get you part marks if you can’t figure
out how to write the code.
# 1: / 6
# 2: / 5
# 3: / 7
# 4: / 6
# 5: / 8
TOTAL: /32
Total Pages = 10 Page 1 cont’d. . .

Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

CSC A08 F Midterm Test Fall 2011
The next two questions involve the sound module that we used in the first assignment. At the end of the
test, you’ll find a list of the sound functions we learned about. Note that you may not need to use all of
them.
You may assume that the sound module has already been imported use the line import sound.
Question 1. [6 marks]
For each part of this question, you need to write a few lines of code. For all three parts, assume that the
variable snd has already been defined and refers to a Sound object.
Part (a) [2 marks] Calling functions
Write code to create a silent Sound of the same length as snd and assign it to the variable silent snd.
Part (b) [2 marks] Looping over a Sound
Write code that prints the value of the left channel of each Sample in snd, each value printed on its own
line.
Part (c) [2 marks] Conditionals in Loops
Write code that prints the index of each Sample in snd for which the left and right channels are equal,
each value printed on its own line.
Page 2 of 10 cont’d. . .

Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

CSC A08 F Midterm Test Fall 2011
Question 2. [5 marks]
Take a look at the following function definition for triple. The triple function will run without error,
but it does not do what the docstring says.
def triple(snd)
’’’Return a copy of Sound snd with the left and right channels tripled.
The original snd is unchanged.’’’
for samp in snd:
left = sound.get_left(samp)
right = sound.get_right(samp)
sound.set_left(samp, left * 3)
sound.set_right(samp, right * 3)
return snd
Part (a) [1 mark] Explain, in English, what is wrong with the triple function as written.
Part (b) [2 marks] In the space above, edit triple so that it performs as the docstring describes. You
may need to add additional lines or code and/or edit existing ones.
Part (c) [2 marks] Write the lines of code that will open a file called ’song.wav’, call triple (assuming
the errors have been fixed), and then play the new song (which will be three times as loud as the original).
Page 3 of 10 cont’d. . .
You're Reading a Preview

Unlock to view full version