CS1114 SAMPLE Test TWO Fall 11SAMPLESAMPLE

SAMPLESAMPLESAMPLE

SAMPLESAMPLE SAMPLE

CS1114

Fall 2009

SECOND Test

NOTE: There isXXX LONGER problem at the end of the test.
A good strategy would be to skip any questions you cannot do quickly

to get to the LONGER problemat the end of the test;
then go back through the shorter ones.

Closed book, closed notes, NO electronic devices of any type

You will have ONE HOUR AND 15 MINUTES to complete this test

Do NOT tear any pages out of your Blue Book.

Do NOT tear any pages from this document.
Be sure to hand in all six pages of this test.

Do not remove this page.

Place your answers for questions 1 through XXX in this document.

If you write any of these answers in your Blue Book you will get
NO CREDIT for them.

Place your answer for questionXXX in your Blue Book.

Put your name and ID on each page and on the cover of the Blue Book.


CIRCLE YOUR LAST NAME

If you need "scratch" paper, use your Blue Book
but cross out anything you do not want graded.

There are XXX questions totaling XXX points

There are no optional questions. You must earnXXXpoints to score a 100%

Do not begin until you are instructed to do so

If you continue writing after time has been called
you will have earned a ZERO.

If your cell phone rings during this test
or if you answer your cellphone, you will receive a ZERO.

All cell phones must be inside bags or pockets during the entire test.
No cell phones are allowed on your desk at any time during the test.
Turn off all cell phones before the test starts

(If you are expecting a call, BEFORE the test starts leave your phone with the test monitor)

page 1 of 6 pages (counting the cover sheet)

CS1114 SAMPLE Test TWO Fall 11SAMPLESAMPLE

SAMPLESAMPLESAMPLE

SAMPLESAMPLE SAMPLE

Circle one answer for each question

1. (3 pts) zeroth = [ ]
otherth = zeroth[ 0 ]

will compile and runwill not compilewill raise an exception at runtime

2. (3 pts)first = [ "first" ]
second = [first] + first

will compile and runwill not compilewill raise an exception at runtime

3. (3 pts) Using Q2, what is the output? print second

TRUE / FALSE questions. Circle your answer

4.(3 pts)The .count() method can only be used on strings and tuples because both are immutable.

(circle your answer)------TRUEFALSE

5.(3 pts)Given this string:

first = [ 'A', 'b', 'C' ]

second = [ first[2], first[0] ]

If there is a syntax error in this code, circle 'there is a syntax error'.
If there is not a syntax error, what value does second refer to? (write that value in the blank)

(circle your answer) there is a syntax error ______

6. (3 pts)A list manages a collection of values.

(circle your answer)TRUEFALSE

7. (3 pts)The empty string''is returned by the .readline() method when there is nothing more to read.

(circle your answer)TRUEFALSE

MULTIPLE CHOICE questionsNOTE: ----- Q7 is circle ALL correct answers; the others are ONE answer

8. (3 pts)def kiwiOrd( passing = 'F', failing = 'T' ):

...

Circle the letter of ALLanswers that will compile or d) if none will:

SAMPLE SAMPLE SAMPLE SAMPL E SAMPLE page 1 of 6 pages (counting the cover sheet)

CS1114 SAMPLE Test TWO Fall 11SAMPLESAMPLE

SAMPLESAMPLESAMPLE

SAMPLESAMPLE SAMPLE

a)kiwiOrd()

b)kiwiOrd(failing = 'A')

c)kiwiOrd('A', passing = 'B')

d)none of thesewill compile

WHAT IS THE OUTPUT questions – write your answer to the right of the question

If the code won't compile or will raise a runtime exception, state this

9.(3 pts) Given that book is a reference to thislist object: [ 1, 2, 3, 4, 5 ].

What is the output?

for page in book:

ndx = book.index( page )

print book[ 3:ndx ]

What is the output?

10.(3 pts)

first = 'first + second'

print first[ :4 ] + first[ 1 ]

print first[ :0 ] + first[ 2 ] + first[ 1:2 ]

11.(3 pts)

first = [ 'first', 'tsrif', '\t\n\ ' ]

for second in first:

print second[ 1 ],

print"T"

12.(3 pts)

first = [ 8, 7, 6, 5, 4 ]

for second in first.reverse():

print second

13.(3 pts)

first = [5, 6, 7 ]

second = [1, 2, 3, 4 ]

second.append( first + [8] )

print second

14.(3 pts)

first = [ 5, 6, 7, 8, 9 ]

first.pop( 3:5 )

print first

15.(3 pts)

first = ["picky", 'picky', '''picky''']

print first.index('picky')

16.(3 pts)

first = [ [1, 3], [-2, -2], [7,6] ]

first.sort()

print first

17.(5 pts)

first = [ [1,2,3], [5,6,7], [8,9] ]

for second in first[1:]:

print second

second.insert( 2, 'A' )

print first

This would be the BLUE BOOK question

SAMPLE SAMPLE SAMPLE SAMPL E SAMPLE page 1 of 6 pages (counting the cover sheet)

CS1114 SAMPLE Test TWO Fall 11SAMPLESAMPLE

SAMPLESAMPLESAMPLE

SAMPLESAMPLE SAMPLE

18. (55 pts) Write a program that will process data about Poly alumni that a user will type in. Some alums are rich and famous and some aren't.Rich and famous alumni are good to know about – they donate money to the school.

One data entry robot will first type in the names of the rich and famous alumni, one name per line.

Here is a sample set of names of the rich and famous alumni,

Anne Murry

Peter Lorie

Assume that no two people who went to Poly have the same name (!) so all the names will be unique.

Another data entry robot will then type in the data for every alumni (rich and famous and not rich and famous).
Each alumni record will be typed on three lines, the first line has the name of an alumnus, the second line has their net worth (in whole dollars) and the third line has their last donation amount (the actual money amount).

Here is a sample alumni dataset that the second data entryrobot created. (Do NOT solve samples).

Anne Murry

10327232

12.34

Ruth Peyser Bacon

28227333

1827.32

Peter Lorie

20028823

82.32

Bale Murray

82329

267.22

Princess Le Tiffany

8237239

54873.23

Data entry robots do not make any typing mistakes.

Your program (your main) should show the amount we expect to get.
Make this display look nice (prettyprinted).

For the shown data, $967644.42is expected.

REQUIRED:
Write a function that fills a list with the rich and famous alumni names read from a file named richies.txt.
Write a function that returns the expected amount of donations using data in a file named allAlums.txt.
The expectation for donations is:
--- for non-rich-and-famous alums we expect they will donate the same amount as their recent donation

--- for the rich and famous, we expect they will donate 3% of their net worth

You are allowed to write more functions, if you think you need them.
You must write docstrings for every function except main.
You do NOT need to write a docstring for the whole program.
You do NOT need to write the #! hack or call main at the bottom.
Start every answer in your blue book on a left hand page. (Of course you won't have a blue book in the lab!)

END OF TEST

page 1 of 6 pages (counting the cover sheet)