Sample Exam 1 - Michigan State University
Fall Semester 07, Dr. Punch. Exam #1 (09/27), 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
--------------------------------------------------
01:E, 02:A, 03:E, 04:B, 05:A, 06:C, 07:D, 08:A, 09:B, 10:C,
11:D, 12:D, 13:C, 14:D, 15:A, 16:D, 17:E, 18:E, 19:D, 20:A,
21:B, 22:E, 23:B, 24:C, 25:A, 26:B
--------------------------------------------------
[pic]
Figure 1
1) Given user input of 11, what value is output by Line 3 in Figure 1?
a) 0
b) 1
c) 2
d) 3
e) None of the above.
2) Given user input of 12, what value is output by Line 4 in Figure 1?
a) 0
b) 1
c) 2
d) 3
e) None of the above
3) What type is referenced by (associated with) userVal in Line 1 of Figure 1?
a) integer
b) float
c) list
d) tuple
e) None of the above.
4) What is the purpose of the = (equal sign) in Line 2 of Figure 1?
a) take the value on the left side and associate it with the variable on the right side
b) take the value on the right side and associate it with the variable on the left side
c) generate a Boolean indicating if the left side has the same value as the right side
d) all of the above, just depends on the type
e) None of the above.
5) What is the purpose of the : (colon) at the end of the while statement in Figure 1?
a) beginning of a compound statement (a suite)
b) end of a compound statement (a suite)
c) indication of a change of control in the program (a modifier)
d) only there to make the program more readable (a kind of comment)
e) None of the above.
6) How large a value can a 32 bit unsigned integer hold?
a) about 16 billion
b) about 8 billion
c) about 4 billion
d) no limit
e) None of the above
7) What is an iterator?
a) a variable that can take on multiple values
b) a method that makes a sequence (like a list or a string)
c) sets the output width for all subsequent output
d) a control statement goes through the elements of a sequence, one at a time
e) None of the above
8) Which of the following represents the Boolean “not” operator?
a) not
b) ~
c) !
d) %
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) lists are mutable, tuples are not
c) tuples are mutable, lists are not
d) you cannot concatenate lists with the + operator
e) None of the above
10) Which of the following is true about the conversion statement as found below
myFloat = 3.14
int(myFloat)
a) permanently change the value of myFloat
b) permanently change the type of myFloat to an integer
c) take the value from myFloat and turn it into an integer, even if some parts of myFloat’s value is lost. Return the integer. myFloat is not changed
d) take the value from myDouble and turn it into an integer only if myDouble is not modified by the conversion. Return the integer. myDouble is not changed
e) None of the above
11) Which of the following describes the advantages of modules?
a) share knowledge with others about how to solve a particular problem
b) saving effort by allowing reuse of code by others
c) verification of the code by use in many other systems
d) All of the above
e) None of the above
[pic]
Figure 2
12) Given the input ‘aabbcc’ what output is produced by Line2 in Figure 2?
a) ‘aa’
b) ‘bb’
c) ‘cc’
d) ‘bbcc’
e) None of the above
13) Given the input ‘aaccbb’ what output is produced by Line2 in Figure 2?
a) ‘aa’
b) ‘bb’
c) ‘cc’
d) ‘bbcc’
e) None of the above
14) Given the input ‘abcc’ what output is produced by Line3 in Figure 2?
a) 1
b) 2
c) 3
d) 4
e) None of the above
15) What is the purpose of the break statement in Line 1 of 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
16) Which of the following is a true statement(s) about Python slicing?
a) a range, indicated with a ‘:’ , is a half-open range
b) a negative number starts counting from the end of the string
c) the first element in a string begins at index 0
d) All of the above
e) None of the above
[pic]
Figure 3
17) Given the input 10 what output is produced by Line 2 of Figure 3?
a) 0
b) 3
c) 14
d) 18
e) None of the above
18) Given the input 11 what output is produced by Line 3 of Figure 3?
a) 4
b) 5
c) 6
d) 7
e) None of the above
19) Which of the following is a reasonable replacement for Line 1 in Figure 3?
a) extra++
b) ++extra
c) extra =+ 1
d) extra += 1
e) None of the above
20) If Line 1 were removed from Figure 3, which of the following statements would be true?
a) no runtime errors
b) extra would always print 1
c) error, would run past the end of the range
d) All of the above
e) None of the above
[pic]
Figure 4
1) Given the input ‘a*b*1*.*T’ what output is produced by Line 3 of Figure 4?
a) [‘a’,’X’,’b’,’X’,’1’,’X’]
b) [‘a’,’X’,’b’,’X’,1,’X’]
c) [‘a’,’*’,’b’,’*’,1,’*’]
d) [‘a’,’X’,’b’,’X’,1,’X’,’.’,’T’]
e) None of the above
2) Given the input ‘3.14159’ what output is produced by Line 2 of Figure 4?
a) 4
b) 5
c) 6
d) 7
e) None of the above
3) Given the input ‘$100’ what output is produced by Line 4 of Figure 4?
a) False
b) True
c) 0
d) 1
e) None of the above
4) If Line 1 were changed to indx = indx + 2 in Figure 4, the effect would be?
a) No effect
b) error, infinite loop
c) the program would only process every other character
d) error, index beyond the length of the string
e) None of the above
5) What kind of type can the variable indx in Figure 4 hold?
a) no restriction, can contain a value of any type
b) restricted to holding integer types
c) restricted to holding string types
d) restricted to holding any sequence type (string, list, tuple, etc)
e) None of the above
6) Which of the following are true statements regarding for loops and while loops?
a) only a for loop can iterate through a sequence
b) a while loop is the more general “looping statement” of the two
c) the for loop requires a boolean in its statement header
d) All of the above
e) None of the above
27) Write a small program question
20pts. Please, write on scrap paper first, then copy your answer to the next page . Make sure you put your name on the solution and hand it in at the end of the test.
Backround
The Fibonacci sequence works as follows:
• element 0 has the value 0
• element 1 has the value 1
• every element after that has the value of the sum of the two preceding elements
The beginning of the sequence looks like:
0,1,1,2,3,5,8,13,21,34,… for example
• element 6 has the value 8, the sum of element 4(3) and element 5(5)
• element 7 has the value 13, the sum of element 5(5) and element 6(8)
Requirements
Your program prompts for an element, and prints out the value of that element of the Fibonacci sequence. Thus:
• input 7, produces 13
• input 9, produces 34
Hints
• Don’t try to just type out the entire list. It gets big very fast. Element 25 is 75205. Element 100 is 354224848179261915075. Write a program!
• Start with a properly initialized list and add on to it until you reach the element you are looking for. Then print out that element
• efficiency and/or elegance is not required. Does it work is all that matters!
• be clear about your indentation!
CSE 231, Fall 07, Dr. Punch, Exam 1 written solution
Name:
Section:
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- python for kids lesson plan no starch press
- sample exam 1 michigan state university
- markov models numpy github pages
- assignment no
- research ideas northwestern university
- dictionaries github pages
- chapter 1 scalar variables and data types
- introduction stellenbosch university
- laboratory manual for computer programming with python
Related searches
- michigan state university job postings
- michigan state university philosophy dept
- michigan state university online degrees
- michigan state university employee discounts
- michigan state university employee lookup
- michigan state university employee portal
- michigan state university employee salaries
- michigan state university admissions
- michigan state university employee benefits
- michigan state university website
- michigan state university employee directory
- michigan state university deadline