python测试题_第1页
python测试题_第2页
python测试题_第3页
python测试题_第4页
python测试题_第5页
已阅读5页,还剩23页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1.what does the following code do?(B) def a(b, c, d): pass A.defines a list and initializes it B.defines a function, which does nothing C.defines a function, which passes its parameters through D.defines an empty class 2.what gets printed? Assuming python version 2.x(A) print type(1/2) A. B. C. D. E

2、. 3. what is the output of the following code?(E) print type(1,2) A. B. C. D. E. 4. what gets printed?(C) def f(): pass print type(f() A. B. C. D. E. 5. what should the below code print?(A) print type(1J) A. B. C. D. E. 6. what is the output of the following code?(D) print type(lambda:None) A. B. C.

3、 D. E. 7. what is the output of the below program?(D) a = 1,2,3,None,(), print len(a) A.syntax error B.4 C.5 D.6 E.7 8.what gets printed? Assuming python version 3.x(C) print (type(1/2) A. B. C. D. E. 9. What gets printed?(C) d = lambda p: p * 2 t = lambda p: p * 3 x = 2 x = d(x) x = t(x) x = d(x) p

4、rint x A.7 B.12 C.24 D.36 E.48 10. What gets printed?(A) x = 4.5 y = 2 print x/y A.2.0 B.2.25 C.9.0 D.20.25 E.21 11. What gets printed?(C) nums = set(1,1,2,3,3,3,4) print len(nums) A.1 B.2 C.4 D.5 E.7 12. What gets printed?(A) x = True y = False z = False if x or y and z: print yes else: print no A.

5、yes B.no C.fails to compile 13. What gets printed?(C) x = True y = False z = False if not x or y: print 1 elif not x or not y and z: print 2 elif not x or y or not y and x: print 3 else: print 4 A.1 B.2 C.3 D.4 14. If PYTHONPATHis set in the environment, which directories are searched for modules?(D

6、) A) PYTHONPATH directory B) current directory C) home directory D) installation dependent default path A.A only B.A and D C.A, B, and C D.A, B, and D E.A, B, C, and D 15. In python 2.6 or earlier, the code will print error type 1 if accessSecureSystem raises an exception of either AccessError type

7、or SecurityError type(B) try: accessSecureSystem() except AccessError, SecurityError: print error type 1 continueWork() A.true B.false 16. The following code will successfully print the days and then the months(B) daysOfWeek = Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday months =Ja

8、n, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec print DAYS: %s, MONTHS %s % (daysOfWeek, months) A.true B.false 17. Assuming python 2.6 what gets printed?(A) f = None for i in range (5): with open(data.txt, w) as f: if i 2: break print f.closed A.True B.False C.None 18. What gets printed?(C

9、) counter = 1 def doLotsOfStuff(): global counter for i in (1, 2, 3): counter += 1 doLotsOfStuff() print counter A.1 B.3 C.4 D.7 E.none of the above 19. What gets printed?(C) print rnwoow A.new line then the string: woow B.the text exactly like this: rnwoow C.the text like exactly like this: nwoow D

10、.the letter r and then newline then the text: woow E.the letter r then the text like this: nwoow 20.What gets printed?(B) print hello world A.on one line the text: hello world B.on one line the text: helloworld C.hello on one line and world on the next line D.syntax error, this python program will n

11、ot run 21.What gets printed?(E) print x48x49! A.x48x49! B.4849 C.4849! D.4849! E.HI! 22. What gets printed?(D) print 0 xA + 0 xa A.0 xA + 0 xa B.0 xA 0 xa C.14 D.20 E.0 x20 23. What gets printed?(E) class parent: def _init_(self, param): self.v1 = param class child(parent): def _init_(self, param):

12、self.v2 = param obj = child(11) print %d %d % (obj.v1, obj.v2) A.None None B.None 11 C.11 None D.11 11 E.Error is generated by program 24. What gets printed?(E) kvps= user,bill, password,hillary print kvpspassword A.user B.bill C.password D.hillary E.Nothing. Python syntax error 25. What gets printe

13、d?(B) 66% on 1871 times asked class Account: def _init_(self, id): self.id = id id = 666 acc = Account(123) print acc.id A.None B.123 C.666 D.SyntaxError, this program will not run 26. What gets printed?(C) name = snow storm print %s % name6:8 A.st B.sto C.to D.tor E.Syntax Error 27. What gets print

14、ed?(D) name = snow storm name5 = X print name A.snow storm B.snowXstorm C.snow Xtorm D.ERROR, this code will not run 28. Which numbers are printed?(C) for i inrange(2): print i for i in range(4,6): print i A.2, 4, 6 B.0, 1, 2, 4, 5, 6 C.0, 1, 4, 5 D.0, 1, 4, 5, 6, 7, 8, 9 E.1, 2, 4, 5, 6 29. What se

15、quence of numbers is printed?(B) values = 1, 2, 1, 3 nums = set(values) def checkit(num): if num in nums: return True else: return False for i infilter(checkit, values): print i A.1 2 3 B.1 2 1 3 C.1 2 1 3 1 2 1 3 D.1 1 1 1 2 2 3 3 E.Syntax Error 30. What sequence of numbers is printed?(E) values =

16、2, 3, 2, 4 def my_transformation(num): return num * 2 for i inmap(my_transformation, values): print i A.2 3 2 4 B.4 6 4 8 C.1 1.5 1 2 D.1 1 1 2 E.4 9 4 16 31. What numbers get printed(C) import pickle class account: def _init_(self, id, balance): self.id = id self.balance = balance def deposit(self,

17、 amount): self.balance += amount def withdraw(self, amount): self.balance -= amount myac = account(123, 100) myac.deposit(800) myac.withdraw(500) fd = open( archive, w ) pickle.dump( myac, fd) fd.close() myac.deposit(200) print myac.balance fd = open( archive, r ) myac = pickle.load( fd ) fd.close()

18、 print myac.balance A.500 300 B.500 500 C.600 400 D.600 600 E.300 500 32. What gets printed by the code snippet below?(B) import math print math.floor(5.5) A.5 B.5.0 C.5.5 D.6 E.6.0 33. What gets printed by the code below?(E) class Person: def _init_(self, id): self.id = id obama = Person(100) obama

19、._dict_age = 49 print obama.age + len(obama._dict_) A.1 B.2 C.49 D.50 E.51 34. What gets printed?(E) x = foo y = 2 print x + y A.foo B.foo foo C.foo 2 D.2 E.An exception is thrown 35. What gets printed?(E) def simpleFunction(): This is a cool simple function that returns 1 return 1 print simpleFunct

20、ion._doc_10:14 A.simpleFunction B.simple C.func D.funtion E.cool 36. What does the code below do?(C) sys.path.append(/root/mods) A.Changes the location that the python executable is run from B.Changes the current working directory C.Adds a new directory to seach for python modules that are imported

21、D.Removes all directories for mods E.Changes the location where sub-processes are searched for after they are launched 37. What gets printed?(C) import re sum = 0 pattern = back if re.match(pattern, backup.txt): sum += 1 if re.match(pattern, text.back): sum += 2 if re.search(pattern, backup.txt): su

22、m += 4 if re.search(pattern, text.back): sum += 8 print sum A.3 B.7 C.13 D.14 E.15 38. Which of the following print statements will print all the names in the list on a seperate line(A) names = Ramesh, Rajesh, Roger, Ivan, Nico A.print n.join(names) B.print names.join(n) C.print names.concatenate(n)

23、 D.print names.append(n) E.print names.join(%sn, names) 39. True or false? Code indentation must be 4 spaces when creating a code block?(B) if error: # four spaces of indent are used to create the block print %s % msg A.True B.False 40. Assuming the filename for the code below is /usr/lib/python/per

24、son.py and the program is run as: python /usr/lib/python/person.py What gets printed?(D) class Person: def _init_(self): pass def getAge(self): print _name_ p = Person() p.getAge() A.Person B.getAge C.usr.lib.python.person D._main_ E.An exception is thrown 41. What gets printed(B) foo = print type(f

25、oo) A.set B.dict C.list D.tuple E.object 42. What gets printed?(C) foo = (3, 4, 5) print type(foo) A.int B.list C.tuple D.dict E.set 43. What gets printed?(D) country_counter = def addone(country): if country in country_counter: country_countercountry += 1 else: country_countercountry = 1 addone(Chi

26、na) addone(Japan) addone(china) print len(country_counter) A.0 B.1 C.2 D.3 E.4 44. What gets printed?(D) confusion = confusion1 = 1 confusion1 = 2 confusion1 += 1 sum = 0 for k in confusion: sum += confusionk print sum A.1 B.2 C.3 D.4 E.5 45. What gets printed?(C) confusion = confusion1 = 1 confusio

27、n1 = 2 confusion1.0 = 4 sum = 0 for k in confusion: sum += confusionk print sum A.2 B.4 C.6 D.7 E.An exception is thrown 46.What gets printed?(E) boxes = jars = crates = boxescereal = 1 boxescandy = 2 jarshoney = 4 cratesboxes = boxes cratesjars = jars print len(cratesboxes) A.1 B.2 C.4 D.7 E.An exc

28、eption is thrown 47. What gets printed?(E) numberGames = numberGames(1,2,4) = 8 numberGames(4,2,1) = 10 numberGames(1,2) = 12 sum = 0 for k in numberGames: sum += numberGamesk print len(numberGames) + sum A.8 B.12 C.24 D.30 E.33 48. What gets printed?(A) foo = 1:1, 2:2, 3:3 foo = print len(foo) A.0

29、B.1 C.2 D.3 E.An exception is thrown 49. What gets printed?(B) foo = 1:1, 2:2, 3:3 del foo1 foo1 = 10 del foo2 print len(foo) A.1 B.2 C.3 D.4 E.An exception is thrown 50. What gets printed?(E) names = Amir, Barry, Chales, Dao print names-1-1 A.A B.r C.Amir D.Dao E.o 51. What gets printed?(B) names1

30、= Amir, Barry, Chales, Dao names2 = names1 names3 = names1: names20 = Alice names31 = Bob sum = 0 for ls in (names1, names2, names3): if ls0 = Alice: sum += 1 if ls1 = Bob: sum += 10 print sum A.11 B.12 C.21 D.22 E.33 52. What gets printed?(E) names1 = Amir, Barry, Chales, Dao loc = names1.index(Edw

31、ard) print loc A.-1 B.0 C.4 D.Edward E.An exception is thrown 53. What gets printed?(B) names1 = Amir, Barry, Chales, Dao if amir in names1: print 1 else: print 2 A.1 B.2 C.An exception is thrown 54. What gets printed?(C) names1 = Amir, Barry, Chales, Dao names2 = name.lower() for name in names1 pri

32、nt names220 A.i B.a C.c D.C E.An exception is thrown 55. What gets printed?(B) numbers = 1, 2, 3, 4 numbers.append(5,6,7,8) print len(numbers) A.4 B.5 C.8 D.12 E.An exception is thrown 56. Which of the following data structures can be used with the in operator to check if an item is in the data stru

33、cture?(E) A.list B.set C.dictionary D.None of the above E.All of the above 57. Wat gets printed?(D) list1 = 1, 2, 3, 4 list2 = 5, 6, 7, 8 print len(list1 + list2) A.2 B.4 C.5 D.8 E.An exception is thrown 58. What gets printed?(C) def addItem(listParam): listParam += 1 mylist = 1, 2, 3, 4 addItem(myl

34、ist) print len(mylist) A.1 B.4 C.5 D.8 E.An exception is thrown 59. What gets printed?(E) my_tuple = (1, 2, 3, 4) my_tuple.append( (5, 6, 7) ) print len(my_tuple) A.1 B.2 C.5 D.7 E.An exception is thrown 60. What gets printed?(B) a = 1 b = 2 a,b = b,a print %d %d % (a,b) A.1 2 B.2 1 C.An exception i

35、s thrown D.This program has undefined behavior 61. What gets printed?(A) def print_header(str): print +%s+ % str print_header.category = 1 print_header.text = some info print_header(%d %s % (print_header.category, print_header.text) A.+1 some info+ B.+%s+ C.1 D.some info 62. What gets printed?(C) de

36、f dostuff(param1, *param2): print type(param2) dostuff(apples, bananas, cherry, dates) A.str B.int C.tuple D.list E.dict 63. What gets printed?(E) def dostuff(param1, *param2): print type(param2) dostuff(capitals, Arizona=Phoenix, California=Sacramento, Texas=Austin) A.in B.str C.tuple D.list E.dict

37、 64. What gets printed?(B) def myfunc(x, y, z, a): print x + y nums = 1, 2, 3, 4 myfunc(*nums) A.1 B.3 C.6 D.10 E.An exception is thrown 65. How do you create a package so that the following reference will work?(C) p = mytools.myparser.MyParser() A.Declare the myparser package in mytools.py B.Create

38、 an _init_.py in the home dir C.Inside the mytools dir create a _init_.py D.Create a myparser.py directory inside the mytools directory E.This can not be done 66. What gets printed?(E) class A: def _init_(self, a, b, c): self.x = a + b + c a = A(1,2,3) b = getattr(a, x) setattr(a, x, b+1) print a.x

39、A.1 B.2 C.3 D.6 E.7 67. What gets printed?(E) class NumFactory: def _init_(self, n): self.val = n def timesTwo(self): self.val *= 2 def plusTwo(self): self.val += 2 f = NumFactory(2) for m in dir(f): mthd = getattr(f,m) if callable(mthd): mthd() print f.val A.2 B.4 C.6 D.8 E.An exception is thrown 68. What gets printed?(A) one = chr(104) two = chr(105) print %s%s % (one, two) A.hi B.h C.Inside the mytools dir create a _init_.py and myparser.py D.104105 E.104 69. What gets printed?(A) x = 0 y = 1 a = cmp(x,y) if a 2 or num 0: return None return num except: re

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论