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
CSC 111 Exam I. Spring 2008. NAME:__________________________________ March 11, 2008 Open Book, open notes, in-lab, No Computers I. Worth 24 (3 pts each) True or False. Circle One. a) True or False A computer program can write another program. b) True or False A python module (.py file) cannot contain more than one function definition. c) True or False A tuple is like a list, but is not mutable. d) True or False Consider the python statements: x=4 x=x+2 After these statements execute, the variable x will have the value 2. e) True or False monty is a reserved word in Python f) True or False To print out the 'o' in string x = "Python" we would type print x[5]. g) True or False When the following statements execute the user sees 3 2 on the screen: x=2 y=3 if x <5 and y > 2: print x, y h) True or False The division operator (/) gives a floating point result, even if both of the numbers it uses are integers. II. Worth 18 (2 points each). Multiple Choice. Circle one choice. a) After the Python assignment statement: myfile = “public_html/images/taz.gif” is executed, what is the data type of the value in variable myfile? i) int ii) gif iii) string b) If we have the statement canned = [“Linguistics”, “Society”, “Implausibility”] what is len(canned[2]) ? i) 3 ii) 7 iii) 14 c) What do the following Python statements produce? x = "Buckaroo Bonzai" x = x[5:7] + x[5:7] print x i) 'arar' ii) 'roro' iii) 'rooroo' iv) None of the above. d) What does the following definite loop produce? for i in [19,11,5]: print i - 10, i) 9 1 -5 ii) 9 1 -5 iii) -5 1 9 iv) 19 11 5 e) Machine language, the low-level language a CPU understands, has how many "characters"? i) 8 ii) 2 iii) 32 iv) 256 Million f) A CPU does: i) arithmetic and logic operations. ii) anything a human brain does. iii) storing of data, even when the computer is turned off. iv) None of the above. g) The python interpreter is i) a computer ii) a program iii) a hard disk iv) none of the above h) Suppose we have the following three python statements: path = "public_html/" file = "index.html" filename = path+file What is the value stored in variable filename? i) "pathfile" ii) “filepath" iii) "public_html/index.html” iv) "public_html/file" v) none of the above i) Consider the python decision statement x = [2,3,4] if x[2]==4: print "four" else: print "three" What will be printed? i) four ii) three iii) nothing will be printed. III. Worth 40 (10 each) Write program fragments. These do not have to be complete programs. a) Write python statements that use a definite loop and the range() function to print this: -9 -6 -3 0 b) Write a definition of a function with the name sumIt: 1) sumIt has one formal parameter, named nums, which is a list of numbers, and 2) sumIt finds the sum of all the numbers in the list, and prints the sum. c) Assume there is a variable already defined, called CDs, and it contains a list of strings. Also assume there is a variable named titles, initialized to the empty list. Write a definite loop that goes through the list of strings stored in CDs. The body of the loop capitalizes each word in each string in the list, and then appends the capitalized string to the list stored in titles. d) Write a statement that assigns the value 28 to a variable named days when the variable x is 365 and assigns days the value 29 when x is 366. IV. Worth 18 points (2 each). What is wrong? Circle syntax errors in these programs. Assume these are complete, as defined here. Missing comment/documentation is not a syntax error. There are 3 syntax errors in each part. a) b) def mane() print "This program”, “demonstrates errors” x = input(“Enter number” y = x*10 print z input string def main(): author = "Elizabeth Cady Stanton" names = string.split(author) print "third name is" names[2] first = raw_input("Guess the first name") if atfirst == "Elizabeth": print "Yay, do you know of this pioneer?" else: print "Wrong again!" c) def max(x,y): if x > y: return x else uturn y def main(): print "I can find a maximum for you" myx = input"Enter first value") myy = input("Enter second value") M = max(myx,myy) print "The maximum is" + str(M)