Sei sulla pagina 1di 9

Fall Semester 09, Dr. Punch.

Exam #1 (10/08), form 1 A

Last name (printed):

First name (printed):

Directions:
a) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD
TO BEGIN.
b) You have 80 minutes to complete the exam (8:30-9:50)
c) This exam booklet contains 26 multiple choice questions, each weighted equally
(5 points) and one 20 point “write some code” question. Nine pages total
d) You may use one 8.5" x 11" note sheet during the exam. No other reference
materials or calculating devices may be used during the examination.
e) Questions will not be interpreted during the examination.
f) You should choose the single best alternative for each question, even if you
believe that a question is ambiguous or contains a typographic error.
g) Please fill in the requested information at the top of this exam booklet.
h) Use a #2 pencil to encode any information on the OMR form.
i) Please encode the following on the OMR form:
 Last name and first initial
 MSU PID
 Exam form (see the title of this page)
j) Please sign the OMR form.
k) Only answers recorded on your OMR form will be counted for credit.
l) Completely erase any responses on the OMR form that you wish to delete.
m) You must turn in this exam booklet and the OMR form when you have completed
the exam. When leaving, please be courteous to those still taking the exam.

Good luck.

Timing tip. A rate of 2.5 minute per multiple choice problem leaves 15 minutes to write
the 20 point program at the end

KEY
1 2 3 4 5 6 7 8 9 10
A E A C D D E E D B

11 12 13 14 15 16 17 18 19 20
C BC C A E B C A E B

21 22 23 24 25 26
A C D B ABCDE CE
Figure 1

1) Given user input of 11, how many times is Line 1 in Figure 1 executed?
a) 1
b) 2
c) 3
d) 4
e) None of the above.
2) Given user input of 12, what output is produced by Line 2 in Figure 1?
a) 0
b) 1
c) 2
d) 3
e) None of the above
3) Given user input of 13, what output is produced by Line 3 in Figure 1?
a) 0
b) 1
c) 2
d) 3
e) None of the above.
4) Given user input of 14, what output is produced by Line 4 in Figure 1?
a) 0
b) 1
c) 2
d) 3
e) None of the above.
5) Which of the following statements is true about the assignment statement?
a) associates the value on the rhs with the variable on the lhs
b) does not return a value
c) is represented by the = sign
d) All of the above
e) None of the above.

2
6) 232 is about equal to what integer value?
a) about 32 billion
b) about 16 billion
c) about 8 billion
d) about 4 billion
e) None of the above

7) Which of the following values represents a False Boolean in Python?


a) ‘False’
b) 100
c) 3.14159
d) True
e) None of the above

8) For the variable myVar associated with an integer value, which of the following is
equivalent to the statement 5 <= myVar <= 10 ?
a) myVar <= 10
b) myVar >= 5 or myVar <= 10
c) myVar <= 5 and myVar >= 10
d) myVar > 6 and myVar < 11
e) None of the above.

9) Which of the following statements are true about the differences between lists and
tuples?
a) they differ in the kinds of objects they can hold
b) you cannot concatenate lists with the + operator
c) tuples do not have an associated length (via the len function)
d) lists are mutable, tuples are not
e) None of the above

10) What is the correct result for the expression len(range(1,6))?


a) 6
b) 5
c) 4
d) 3
e) None of the above

11) Which of the following are true when describing the differences between Python’s
for and while statements?
a) for is a compound statement, while is not
b) for is a more general statement than while
c) for requires a data structure to iterate through, while does not
d) All of the above
e) None of the above

3
Figure 2

12) Given the input ‘lmn’ what output is produced by Line1 in Figure 2?
a) 1
b) 2
c) 3
d) ‘1’
e) None of the above
13) Given the input ‘abc’ what output is produced by Line2 in Figure 2?
a) ‘a’
b) ‘b’
c) ‘c’
d) ‘abc’
e) None of the above
14) Given the input ‘bill’ what output is produced by Line 3 in Figure 2?
a) ‘bill’
b) ‘llib’
c) ‘’
d) ‘m’
e) None of the above
15) Given the input ‘happy’ what output is produced by Line3 in Figure 2?
a) ‘happy’
b) ‘yppah’
c) ‘’
d) ‘m’
e) None of the above
16) What is the purpose of the continue statement in Figure 2?
a) exit the loop
b) exit the present iteration of the loop, continue from the top of the loop
c) skip the next statement and then continue
d) halt the entire program
e) None of the above

4
Figure 3
17) Given the input 4 what output is produced by Line2 of Figure 3?
a) 3
b) 2
c) 1
d) 0
e) None of the above
18) Given the input 5 what output is produced by Line3 of Figure 3?
a) 31
b) 32
c) 4
d) 0
e) None of the above
19) Given the input 5 what output is produced by Line4 of Figure 3?
a) 31
b) 32
c) 4
d) 0
e) None of the above
20) If Line1 were modified to be current=(current*3)+1, what effect would it
have on the program with an input of 5?
a) error, ran over the end of the string
b) no change, works just as before
c) would not examine the element of the sequence
d) error, infinite loop
e) None of the above

5
Figure 4

21) Given a first input of 54321 and a second input of 3, what result is produced by
Line3 of Figure 4?
a) 10
b) 15
c) 0
d) 1
e) None of the above
22) Given a first input of 12345 and a second input of 3, what result is produced by
Line3 of Figure 4?
a) 10
b) 15
c) 0
d) 1
e) None of the above
23) Given a first input of 12345 and a second input of 3, what result is produced by
Line4 of Figure 4?
a) 12345
b) 54321
c) 34512
d) 45123
e) None of the above
24) Given a first input of 54321 and a second input of 5, what result is produced by
Line4 of Figure 4?
a) 12345
b) 54321
c) 45123
d) 34512
e) None of the above

6
25) If Line1 of Figure 4 were modified to be indx = 0, what effect would that have
on the program with a first input of 12 and a second input of 1?
a) index error, indexing outside of defined boundaries
b) no change, it would run just as before
c) the value printed by Line4 would change
d) infinite loop error, the program would never end
e) None of the above

26) Which of the following are an equivalent statement for Line2 of Figure 4?
a) for indx in range(0,len(userVal)):
b) for indx in range(1,len(userVal)-1)):
c) while index < len(userVal):
d) All of the above
e) None of the above

7
27) Write a small program question

20pts. Please, write on scrap paper first, then copy your answer to the next page

Requirements
Your program prompts for a string, a mixture of digits and non-digits. You are to:
• print the sequence of non-digits in the provided string (including an empty sequence)
• print the sequence of digits in the provided string (including an empty sequence)
• if digits are found, add the digits and the reverse of the digits together and print the
sum
• if no digits are found, print that no digits were found and do not calculate any sum

Below are some examples.


>>>
Give me a string:abcdefg
The digits are: and the non-digits are:abcdefg
There were no digits to sum together
>>>
Give me a string:a1b2c3
The digits are:123 and the non-digits are:abc
The sum of 123 and its reverse 321 is:444

Hints
• efficiency and/or elegance is not required. Does it work is all that matters!
• readability DOES MATTER. Make it readable!
• be clear about your indentation!

8
Name:

Section:

Potrebbero piacerti anche