Quiznetik

Problem Solving and Python Programming | Set 4

1. Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use?

Correct : B. len(d)

2. print(list(d.keys()))

Correct : A. [“john”, “peter”]

3. Which of these about a dictionary is false?

Correct : B. the keys of a dictionary can be accessed using values

4. Which of the following is not a declaration of the dictionary?

Correct : C. {1,”a”,2”b”}

5. ,4))

Correct : B. a

6. ,4))

Correct : D. 4

7. ,"D") print(a)

Correct : A. {1: ‘a’, 2: ‘b’, 3: ‘c’, 4: ‘d’}

8. Which of the following isn’t true about dictionary keys?

Correct : C. keys must be integers

9. ) print(a)

Correct : B. {1: 5, 2: 3}

10. ,9))

Correct : A. 9

11. Which of the statements about dictionary values if false?

Correct : C. values of a dictionary must be unique

12. If a is a dictionary with some key-value pairs, what does a.popitem() do?

Correct : A. removes an arbitrary element

13. ][1])

Correct : B. 3

14. ,2,3],"check")

Correct : B. {1:”check”,2:”check”,3:”check”}

15. If b is a dictionary, what does any(b) do?

Correct : A. returns true if any key of the dictionary is true

16. To open a file c:\scores.txt for writing, we use

Correct : B. outfile = open(“c:\\scores.txt”, “w”)

17. To open a file c:\scores.txt for appending data, we use

Correct : A. outfile = open(“c:\\scores.txt”, “a”)

18. Which of the following statements are true?

Correct : D. all of the mentioned

19. 1 TEXT FILES, READING AND WRITING FILES, FORMAT OPERATOR

Correct : A. infile.read(2)

20. print(f.closed)

Correct : A. true

21. Which are the two built-in functions to read a line of text from standard input, which by default comes from the keyboard?

Correct : A. raw_input & input

22. Which one of the following is not attributes of file?

Correct : C. rename

23. What is the use of tell() method in python?

Correct : A. tells you the current position within the file

24. What is the current syntax of rename() a file?

Correct : A. rename(current_file_name, new_file_name)

25. fo.close()

Correct : C. displays output

26. What is the use of seek() method in files?

Correct : A. sets the file’s current position at the offset

27. What is the use of truncate() method in file?

Correct : A. truncates the file size

28. Which is/are the basic I/O connections in file?

Correct : D. all of the mentioned

29. sys.stdout.write('Python\n')

Correct : D. hello python

30. What is the pickling?

Correct : A. it is used for object serialization

31. What is unpickling?

Correct : B. it is used for object deserialization

32. What is the correct syntax of open() function?

Correct : B. file object = open(file_name [, access_mode][, buffering])

33. fo.close()

Correct : D. flushes the file when closing them

34. Correct syntax of file.writelines() is?

Correct : C. fileobject.writelines(sequence)

35. Correct syntax of file.readlines() is?

Correct : A. fileobject.readlines( sizehint );

36. In file handling, what does this terms means “r, a”?

Correct : A. read, append

37. What is the use of “w” in file handling?

Correct : B. write

38. What is the use of “a” in file handling?

Correct : C. append

39. Which function is used to read all the characters?

Correct : A. read()

40. Which function is used to read single line from file?

Correct : B. readlines()

41. Which function is used to write all the characters?

Correct : A. write()

42. Which function is used to write a list of string in a file?

Correct : A. writeline()

43. Which function is used to close a file in python?

Correct : A. close()

44. Is it possible to create a text file in python?

Correct : A. yes

45. Which of the following are the modes of both writing and reading in binary format in file?

Correct : A. wb+

46. Which of the following is not a valid mode to open a file?

Correct : B. rw

47. Which of the following is not a valid attribute of a file object (fp)?

Correct : D. fp.size

48. How do you close a file object (fp)?

Correct : C. fp.close()

49. How do you get the current position within the file?

Correct : B. fp.tell()

50. How do you rename a file?

Correct : B. os.rename(existing_name, new_name)

51. How do you delete a file?

Correct : C. os.remove(‘file’)

52. How do you change the file position to an offset value from the start?

Correct : A. fp.seek(offset, 0)

53. What happens if no arguments are passed to the seek function?

Correct : D. error

54. Which function overloads the == operator?

Correct : A. eq    ()

55. Which operator is overloaded by     lg    ()?

Correct : D. none of the mentioned

56. Which function overloads the >> operator?

Correct : D. none of the mentioned

57. Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?

Correct : A. add    (),     str    ()

58. Which function overloads the // operator?

Correct : C. floordiv    ()

59. How many except statements can a try- except block have?

Correct : D. more than zero

60. When is the finally block executed?

Correct : D. always

61. What happens when ‘1’ == 1 is executed?

Correct : B. we get a false

62. Which of the following is not an exception handling keyword in Python?

Correct : C. accept

63. )) type(g)

Correct : D. class <’generator’>

64. + '3'

Correct : D. typeerror

65. 43')

Correct : B. valueerror

66. Which of the following statements is true?

Correct : A. the standard exceptions are automatically imported into python programs

67. Which of the following is not a standard exception in Python?

Correct : C. assignmenterror

68. Syntax errors are also known as parsing errors.

Correct : A. true

69. An exception is

Correct : A. an object

70. exceptions are raised as a result of an error in opening a particular file.

Correct : D. ioerror

71. Which of the following blocks will be executed whether an exception is thrown or not?

Correct : C. finally

72. Which of these definitions correctly describes a module?

Correct : B. design and implementation of specific functionality to be incorporated into a program

73. Which of the following is not an advantage of using modules?

Correct : C. provides a means of reducing the size of the program

74. Program code making use of a given module is called a              of the module.

Correct : A. client

75. is a string literal denoted by triple quotes for providing the specifications of certain program elements.

Correct : D. docstring

76. Which of the following is true about top- down design process?

Correct : C. the overall design of the program is addressed before the details

77. In top-down design every module is broken into same number of submodules.

Correct : B. false

78. All modular designs are because of a top- down design process.

Correct : B. false

79. Which of the following is not a valid namespace?

Correct : B. public namespace

80. Which of the following is false about “import modulename” form of import?

Correct : A. the namespace of imported module becomes part of importing module

81. Which of the following is false about “from-import” form of import?

Correct : B. this form of import prevents name clash

82. Which of the statements about modules is false?

Correct : C. in the “from-import” form of import, all identifiers regardless of whether they are private or public are imported

83. What is the order of namespaces in which Python looks for an identifier?

Correct : B. python first searches the local namespace, then the global namespace and finally the built-in namespace

84. What type of a structure is this?

Correct : B. case

85. are identified by their addresses, we give them names (field names / variable names) using words.

Correct : B. memory locations

86. Operators with the same precedence are evaluated in which manner?

Correct : A. left to right

87. The expression Int(x) implies that the variable x is converted to integer.

Correct : A. true

88. Hence the result of this expression is 27.2.

Correct : C. 1.7 % 2

89. x75

Correct : C. 117

90. -2)+bin(12^4)

Correct : D. 0b10000b1000

91. :]: print(i, end = " ")

Correct : C. no output

92. } and {name2}".format( name1='foo', name2='bin'))

Correct : A. hello foo and bin

93. ,4,0,6])

Correct : C. false

94. >8, 4>2, 1>2])

Correct : B. true

95. ,4,6) sum([1,2,3])

Correct : A. error, 6

96. eval('x^2')

Correct : B. 1

97. , 4, 6])

Correct : A. 4

98. ) oct(‘7’)

Correct : C. 07

99. Which keyword is used for function?

Correct : C. def

100. Which are the advantages of functions in python?

Correct : D. all of the mentioned