Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Spring Semester 08, Dr. Punch. Exam #1 (2/12), form 1 B 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 (12:40-2:00 pm) 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 A A 3 C 4 E 5 D 6 C 7 B 8 C 9 B 11 D 12 C 13 A 14 B 15 E 16 A 17 D 18 C 19 E 21 E 22 D 23 B 24 C 25 A 26 B 10 E 20 B Figure 1 1) Given the input ‘abc’ what output is produced by Line1 in Figure 1? a) ‘abc’ b) ‘bca’ c) ‘baa’ d) ‘bcc’ e) None of the above 2) Given the input ‘aabb’ what output is produced by Line1 in Figure 1? a) ‘baa b) ‘aabb’ c) ‘bba’ d) ‘abb’ e) None of the above 3) Given the input ‘bccc’ what output is produced by Line1 in Figure 1? a) bcc b) bccc c) ccc d) bbc e) None of the above 4) Given the input ‘ccbb’ what output is produced by Line1 in Figure 1? a) bcc b) bccc c) ccc d) bbc e) None of the above 5) 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 starting with -1 c) the first element in a string begins at index 0 d) All of the above e) None of the above 6) As an approximation, every 3 powers of 10 are about equal to what? a) 3 powers of 2 (103 ~ 23) b) 8 powers of 2 (103 ~ 28) c) 10 powers of 2 (103 ~ 210) d) 16 powers of 2 (103 ~ 216) e) None of the above 7) What is the index of the last element of every string? a) len(s) b) len(s) -1 c) len(s-1) d) -2 e) None of the above 8) Python is an interpreted language. What does the term interpreted mean? a) Python ‘understands’ the language and does what is required b) Python converts a program into machine language so it can be run c) Python runs each line of the program, one line at a time d) Python requires a special kind of CPU to be able to operate e) None of the above. 9) What is a namespace a) A list of Python names b) A list of Python names and the values they are associated with. c) The list of allowable names that can be used in Python d) All of the above e) None of the above 10) Given the python statement myFloat = 3.14 which of the following statements are true a) myFloat can only hold floating point values b) myFloat can only hold integer values c) myFloat can only hold any numeric value d) myFloat cannot hold Boolean values 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) c) d) e) saving effort by allowing reuse of code by others verification of the code by use in many other systems All of the above None of the above Figure 2 12) Given user input of 0, what value does the program in Figure 2 print? a) A b) B c) C d) D e) None of the above. 13) Given user input of 2, what value does the program in Figure 2 print? a) A b) B c) C d) D e) None of the above. 14) Given user input of 3, what value does the program in Figure 2 print? a) A b) B c) C d) D e) None of the above. 15) What input causes the else clause of Line 2 to be executed in Figure 2 a) odd integers b) even integers c) integers evenly divisible by three d) negative integers e) None of the above. 16) What is the purpose of the : (colon) at the end of Line 1 of Figure 2 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. Figure 3 17) Given the input ‘abc123’what output is produced by Line 2 of Figure 3? a) [‘a’, ‘b’, ‘c’, ‘1’, ‘2’, ‘3’] b) [‘1’, ‘2’, ‘3’, ‘a’, ‘b’, ‘c’] c) [‘0’, ‘1’, ‘2’, ‘a’, ‘b’, ‘c’] d) [‘0’, ‘1’, ‘2’, ‘b’, ‘c’, ‘d’] e) None of the above 18) Given the input ‘3.14159’ what output is produced by Line 3 of Figure 3? a) 4 b) 5 c) 6 d) 7 e) None of the above 19) Given the input ‘$1000’ what output is produced by Line 4 of Figure 3? a) 1 b) 2 c) 3 d) 4 e) None of the above 20) If Line 1 were removed from Figure 3, what effect would it have? a) No effect b) c) d) e) infinite loop depends on the input string error, index beyond the length of the string None of the above Figure 4 21) What output is produced by Line 2 of Figure 4 on the input 1? a) 1 b) 3 c) 9 d) 16 e) None of the above 22) What output is produced by Line 2 of Figure 4 on the input 3? a) 1 b) 3 c) 9 d) 16 e) None of the above 23) What output is produced by Line 2 of Figure 4 on the input 5? a) 5 b) 144 c) 25 d) 256 e) None of the above 24) For the program in Figure 4, what effect would there be in changing Line 1 from count < 5 to count <= 5? a) error, division by 0 b) no change, works exactly as before c) would go through the loop one more time d) error, infinite loop e) None of the above 25) What type does the variable num contain in Figure 4? a) integer b) floating point value c) string d) Boolean e) None of the above 26) 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 Requirements Write a program that: • prompts for two, three digit integers (no error checking required) • combine those two integers into one larger string as follows: o the first integer’s digits make the first, third and fifth character of the string o the second integer’s digits make the second, fourth and sixth character of the string • append the character ‘:’ to the end of the string • print out as indicated below Example • given the inputs 123 456 o prints 142536: • given the inputs 111 222 o prints 121212: Name: Section: