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?
A. d.size()
B. len(d)
C. size(d)
D. d.len()
Correct : B. len(d)
2. print(list(d.keys()))
A. [“john”, “peter”]
B. [“john”:40, “peter”:45]
C. (“john”, “peter”)
D. (“john”:40, “peter”:45)
Correct : A. [“john”, “peter”]
3. Which of these about a dictionary is false?
A. the values of a dictionary can be accessed using keys
B. the keys of a dictionary can be accessed using values
C. dictionaries aren’t ordered
D. dictionaries are mutable
Correct : B. the keys of a dictionary can be accessed using values
4. Which of the following is not a declaration of the dictionary?
A. {1: ‘a’, 2: ‘b’}
B. dict([[1,”a”],[2,”b”]])
C. {1,”a”,2”b”}
D. { }
Correct : C. {1,”a”,2”b”}
5. ,4))
A. 1
B. a
C. 4
D. invalid syntax for get method
Correct : B. a
6. ,4))
A. error, invalid syntax
B. a
C. 5
D. 4
Correct : D. 4
7. ,"D") print(a)
A. {1: ‘a’, 2: ‘b’, 3: ‘c’, 4: ‘d’}
B. none
C. error
D. [1,3,6,10]
Correct : A. {1: ‘a’, 2: ‘b’, 3: ‘c’, 4: ‘d’}
8. Which of the following isn’t true about dictionary keys?
A. more than one key isn’t allowed
B. keys must be immutable
C. keys must be integers
D. when duplicate keys encountered, the last assignment wins
Correct : C. keys must be integers
9. ) print(a)
A. {1: 5}
B. {1: 5, 2: 3}
C. error, syntax error for pop() method
D. {1: 5, 3: 4}
Correct : B. {1: 5, 2: 3}
10. ,9))
A. 9
B. 3
C. too many arguments for pop() method
D. 4
Correct : A. 9
11. Which of the statements about dictionary values if false?
A. more than one key can have the same value
B. the values of the dictionary can be accessed as dict[key]
C. values of a dictionary must be unique
D. values of a dictionary can be a mixture of letters and numbers
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?
A. removes an arbitrary element
B. removes all the key-value pairs
C. removes the key-value pair for the key given as an argument
D. invalid method for dictionary
Correct : A. removes an arbitrary element
13. ][1])
A. [2,3,4]
B. 3
C. 2
D. an exception is thrown
Correct : B. 3
14. ,2,3],"check")
A. syntax error
B. {1:”check”,2:”check”,3:”check”}
C. “check”
D. {1:none,2:none,3:none}
Correct : B. {1:”check”,2:”check”,3:”check”}
15. If b is a dictionary, what does any(b) do?
A. returns true if any key of the dictionary is true
B. returns false if dictionary is empty
C. returns true if all keys of the dictionary are true
D. method any() doesn’t exist for dictionary
Correct : A. returns true if any key of the dictionary is true
16. To open a file c:\scores.txt for writing, we use
A. outfile = open(“c:\\scores.txt”, “w”)
B. outfile = open(“c:\\scores.txt”, “w”)
C. outfile = open(file = “c:\\scores.txt”, “w”)
D. outfile = open(file = “c:\\scores.txt”, “w”)
Correct : B. outfile = open(“c:\\scores.txt”, “w”)
17. To open a file c:\scores.txt for appending data, we use
A. outfile = open(“c:\\scores.txt”, “a”)
B. outfile = open(“c:\\scores.txt”, “rw”)
C. outfile = open(file = “c:\\scores.txt”, “w”)
D. outfile = open(file = “c:\\scores.txt”, “w”)
Correct : A. outfile = open(“c:\\scores.txt”, “a”)
18. Which of the following statements are true?
A. when you open a file for reading, if the file does not exist, an error occurs
B. when you open a file for writing, if the file does not exist, a new file is created
C. when you open a file for writing, if the file exists, the existing file is overwritten with the new file
D. all of the mentioned
Correct : D. all of the mentioned
19. 1 TEXT FILES, READING AND WRITING FILES, FORMAT OPERATOR
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
Correct : A. infile.read(2)
20. print(f.closed)
A. true
B. false
C. none
D. error
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?
A. raw_input & input
B. input & scan
C. scan & scanner
D. scanner
Correct : A. raw_input & input
22. Which one of the following is not attributes of file?
A. closed
B. softspace
C. rename
D. mode
Correct : C. rename
23. What is the use of tell() method in python?
A. tells you the current position within the file
B. tells you the end position within the file
C. tells you the file is opened or not
D. none of the mentioned
Correct : A. tells you the current position within the file
24. What is the current syntax of rename() a file?
A. rename(current_file_name, new_file_name)
B. rename(new_file_name, current_file_name,)
C. rename(()(current_file_name, new_file_name))
D. none of the mentioned
Correct : A. rename(current_file_name, new_file_name)
25. fo.close()
A. compilation error
B. syntax error
C. displays output
D. none of the mentioned
Correct : C. displays output
26. What is the use of seek() method in files?
A. sets the file’s current position at the offset
B. sets the file’s previous position at the offset
C. sets the file’s current position within the file
D. none of the mentioned
Correct : A. sets the file’s current position at the offset
27. What is the use of truncate() method in file?
A. truncates the file size
B. deletes the content of the file
C. deletes the file size
D. none of the mentioned
Correct : A. truncates the file size
28. Which is/are the basic I/O connections in file?
A. standard input
B. standard output
C. standard errors
D. all of the mentioned
Correct : D. all of the mentioned
29. sys.stdout.write('Python\n')
A. compilation error
B. runtime error
C. hello python
D. hello python
Correct : D. hello python
30. What is the pickling?
A. it is used for object serialization
B. it is used for object deserialization
C. none of the mentioned
D. all of the mentioned
Correct : A. it is used for object serialization
31. What is unpickling?
A. it is used for object serialization
B. it is used for object deserialization
C. none of the mentioned
D. all of the mentioned
Correct : B. it is used for object deserialization
32. What is the correct syntax of open() function?
A. file = open(file_name [, access_mode][, buffering])
B. file object = open(file_name [, access_mode][, buffering])
C. file object = open(file_name)
D. none of the mentioned
Correct : B. file object = open(file_name [, access_mode][, buffering])
33. fo.close()
A. compilation error
B. runtime error
C. no output
D. flushes the file when closing them
Correct : D. flushes the file when closing them
34. Correct syntax of file.writelines() is?
A. file.writelines(sequence)
B. fileobject.writelines()
C. fileobject.writelines(sequence)
D. none of the mentioned
Correct : C. fileobject.writelines(sequence)
35. Correct syntax of file.readlines() is?
A. fileobject.readlines( sizehint );
B. fileobject.readlines();
C. fileobject.readlines(sequence)
D. none of the mentioned
Correct : A. fileobject.readlines( sizehint );
36. In file handling, what does this terms means “r, a”?
A. read, append
B. append, read
C. write, append
D. none of the mentioned
Correct : A. read, append
37. What is the use of “w” in file handling?
A. read
B. write
C. append
D. none of the mentioned
Correct : B. write
38. What is the use of “a” in file handling?
A. read
B. write
C. append
D. none of the mentioned
Correct : C. append
39. Which function is used to read all the characters?
A. read()
B. readcharacters()
C. readall()
D. readchar()
Correct : A. read()
40. Which function is used to read single line from file?
A. readline()
B. readlines()
C. readstatement()
D. readfullline()
Correct : B. readlines()
41. Which function is used to write all the characters?
A. write()
B. writecharacters()
C. writeall()
D. writechar()
Correct : A. write()
42. Which function is used to write a list of string in a file?
A. writeline()
B. writelines()
C. writestatement()
D. writefullline()
Correct : A. writeline()
43. Which function is used to close a file in python?
A. close()
B. stop()
C. end()
D. closefile()
Correct : A. close()
44. Is it possible to create a text file in python?
A. yes
B. no
C. machine dependent
D. all of the mentioned
Correct : A. yes
45. Which of the following are the modes of both writing and reading in binary format in file?
A. wb+
B. w
C. wb
D. w+
Correct : A. wb+
46. Which of the following is not a valid mode to open a file?
A. ab
B. rw
C. r+
D. w+
Correct : B. rw
47. Which of the following is not a valid attribute of a file object (fp)?
A. fp.name
B. fp.closed
C. fp.mode
D. fp.size
Correct : D. fp.size
48. How do you close a file object (fp)?
A. close(fp)
B. fclose(fp)
C. fp.close()
D. fp. close ()
Correct : C. fp.close()
49. How do you get the current position within the file?
A. fp.seek()
B. fp.tell()
C. fp.loc
D. fp.pos
Correct : B. fp.tell()
50. How do you rename a file?
A. fp.name = ‘new_name.txt’
B. os.rename(existing_name, new_name)
C. os.rename(fp, new_name)
D. os.set_name(existing_name, new_name)
Correct : B. os.rename(existing_name, new_name)
51. How do you delete a file?
A. del(fp)
B. fp.delete()
C. os.remove(‘file’)
D. os.delete(‘file’)
Correct : C. os.remove(‘file’)
52. How do you change the file position to an offset value from the start?
A. fp.seek(offset, 0)
B. fp.seek(offset, 1)
C. fp.seek(offset, 2)
D. none of the mentioned
Correct : A. fp.seek(offset, 0)
53. What happens if no arguments are passed to the seek function?
A. file position is set to the start of file
B. file position is set to the end of file
C. file position remains unchanged
D. error
Correct : D. error
54. Which function overloads the == operator?
A. eq ()
B. equ ()
C. isequal ()
D. none of the mentioned
Correct : A. eq ()
55. Which operator is overloaded by lg ()?
A. <
B. >
C. !=
D. none of the mentioned
Correct : D. none of the mentioned
56. Which function overloads the >> operator?
A. more ()
B. gt ()
C. ge ()
D. none of the mentioned
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?
A. add (), str ()
B. str (), add ()
C. sum (), str ()
D. str (), sum ()
Correct : A. add (), str ()
58. Which function overloads the // operator?
A. div ()
B. ceildiv ()
C. floordiv ()
D. truediv ()
Correct : C. floordiv ()
59. How many except statements can a try- except block have?
A. zero
B. one
C. more than one
D. more than zero
Correct : D. more than zero
60. When is the finally block executed?
A. when there is no exception
B. when there is an exception
C. only if some condition that has been specified is satisfied
D. always
Correct : D. always
61. What happens when ‘1’ == 1 is executed?
A. we get a true
B. we get a false
C. an typeerror occurs
D. a valueerror occurs
Correct : B. we get a false
62. Which of the following is not an exception handling keyword in Python?
A. try
B. except
C. accept
D. finally
Correct : C. accept
63. )) type(g)
A. class <’loop’>
B. class <‘iteration’>
C. class <’range’>
D. class <’generator’>
Correct : D. class <’generator’>
64. + '3'
A. nameerror
B. indexerror
C. valueerror
D. typeerror
Correct : D. typeerror
65. 43')
A. importerror
B. valueerror
C. typeerror
D. nameerror
Correct : B. valueerror
66. Which of the following statements is true?
A. the standard exceptions are automatically imported into python programs
B. all raised standard exceptions must be handled in python
C. when there is a deviation from the rules of a programming language, a semantic error is thrown
D. if any exception is thrown in try block, else block is executed
Correct : A. the standard exceptions are automatically imported into python programs
67. Which of the following is not a standard exception in Python?
A. nameerror
B. ioerror
C. assignmenterror
D. valueerror
Correct : C. assignmenterror
68. Syntax errors are also known as parsing errors.
A. true
B. false
Correct : A. true
69. An exception is
A. an object
B. a special function
C. a standard module
D. a module
Correct : A. an object
70. exceptions are raised as a result of an error in opening a particular file.
A. valueerror
B. typeerror
C. importerror
D. ioerror
Correct : D. ioerror
71. Which of the following blocks will be executed whether an exception is thrown or not?
A. except
B. else
C. finally
D. assert
Correct : C. finally
72. Which of these definitions correctly describes a module?
A. denoted by triple quotes for providing the specification of certain program elements
B. design and implementation of specific functionality to be incorporated into a program
C. defines the specification of how it is to be used
D. any program that reuses code
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?
A. provides a means of reuse of program code
B. provides a means of dividing up tasks
C. provides a means of reducing the size of the program
D. provides a means of testing individual parts of the program
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.
A. client
B. docstring
C. interface
D. modularity
Correct : A. client
75. is a string literal denoted by triple quotes for providing the specifications of certain program elements.
A. interface
B. modularity
C. client
D. docstring
Correct : D. docstring
76. Which of the following is true about top- down design process?
A. the details of a program design are addressed before the overall design
B. only the details of the program are addressed
C. the overall design of the program is addressed before the details
D. only the design of the program is addressed
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.
A. true
B. false
Correct : B. false
78. All modular designs are because of a top- down design process.
A. true
B. false
Correct : B. false
79. Which of the following is not a valid namespace?
A. global namespace
B. public namespace
C. built-in namespace
D. local namespace
Correct : B. public namespace
80. Which of the following is false about “import modulename” form of import?
A. the namespace of imported module becomes part of importing module
B. this form of import prevents name clash
C. the namespace of imported module becomes available to importing module
D. the identifiers in module are accessed as: modulename.identifier
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?
A. the syntax is: from modulename import identifier
B. this form of import prevents name clash
C. the namespace of imported module becomes part of importing module
D. the identifiers in module are accessed directly as: identifier
Correct : B. this form of import prevents name clash
82. Which of the statements about modules is false?
A. in the “from-import” form of import, identifiers beginning with two underscores are private and aren’t imported
B. dir() built-in function monitors the items in the namespace of the main module
C. in the “from-import” form of import, all identifiers regardless of whether they are private or public are imported
D. when a module is loaded, a compiled version of the module with file extension .pyc is automatically produced
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?
A. python first searches the global namespace, then the local namespace and finally the built- in namespace
B. python first searches the local namespace, then the global namespace and finally the built-in namespace
C. python first searches the built-in namespace, then the global namespace and finally the local namespace
D. python first searches the built-in namespace, then the local namespace and finally the global namespace
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?
A. sequence
B. case
C. repetition
D. process
Correct : B. case
85. are identified by their addresses, we give them names (field names / variable names) using words.
A. memory variables
B. memory locations
C. memory addresses
D. data variables
Correct : B. memory locations
86. Operators with the same precedence are evaluated in which manner?
A. left to right
B. right to left
C. can’t say
D. none of the mentioned
Correct : A. left to right
87. The expression Int(x) implies that the variable x is converted to integer.
A. true
B. false
Correct : A. true
88. Hence the result of this expression is 27.2.
A. 4.7 – 1.5
B. 7.9 * 6.3
C. 1.7 % 2
D. 3.4 + 4.6
Correct : C. 1.7 % 2
89. x75
A. 115
B. 116
C. 117
D. 118
Correct : C. 117
90. -2)+bin(12^4)
A. 0b10000
B. 0b10001000
C. 0b1000b1000
D. 0b10000b1000
Correct : D. 0b10000b1000
91. :]: print(i, end = " ")
A. a a a a a a
B. a
C. no output
D. error
Correct : C. no output
92. } and {name2}".format( name1='foo', name2='bin'))
A. hello foo and bin
B. hello {name1} and {name2}
C. error
D. hello and
Correct : A. hello foo and bin
93. ,4,0,6])
A. error
B. true
C. false
D. 0
Correct : C. false
94. >8, 4>2, 1>2])
A. error
B. true
C. false
D. 4>2
Correct : B. true
95. ,4,6) sum([1,2,3])
A. error, 6
B. 12, error
C. 12, 6
D. error, error
Correct : A. error, 6
96. eval('x^2')
A. error
B. 1
C. 9
D. 6
Correct : B. 1
97. , 4, 6])
A. 4
B. 3
C. error
D. 6
Correct : A. 4
98. ) oct(‘7’)
A. error 07
B. 0o7 error c) 0o7 error d)
C. 07
D. 0o7
Correct : C. 07
99. Which keyword is used for function?
A. fun
B. define
C. def
D. function
Correct : C. def
100. Which are the advantages of functions in python?
A. reducing duplication of code
B. decomposing complex problems into simpler pieces
C. improving clarity of the code
D. all of the mentioned
Correct : D. all of the mentioned