406C - Python Programming

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Dr.G.R.

Damodaran College of Science


(Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Re-
accredited at the 'A' Grade Level by the NAAC and ISO 9001:2008 Certified
CRISL rated 'A' (TN) for MBA and MIB Programmes

II BCA[2018 - 2021 BATCH]


SEMESTER IV
CORE: PYTHON PROGRAMMING - 406C
Multiple Choice Questions.

1. Python was developed by __________________


A. Guido Van Rossum
B. Dennis Ritchie
C. Ken Thnompson
D. Bjarne stroustrup
ANSWER: A

2. Python was developed in the year_______________


A. 2000
B. 1990
C. 1995
D. 1991
ANSWER: D

3. Standard python compiler is written in ___________ language.


A. VC++
B. C++
C. C
D. PERL
ANSWER: C

4. PVM is often called as _____________


A. python interpreter
B. python compiler
C. python volatile machine
D. portable virtual machine
ANSWER: A

5. What is the value of the following expression? Float(11 // 2 + 2 / 2)


A. 6.5
B. 3.25
C. 6.0
D. 5.5
ANSWER: C

6. What is the value of the following expression? 8/4/2, 8/(4/2)


A. 4.0, 1.0
B. 1.0, 4.0
C. 1.0, 1.0
D. 4.0, 4.0
ANSWER: B

7. What will be the value of the following python expression? 9 + 4 % 5


A. 3
B. 13
C. 1
D. 9
ANSWER: B

8. Which among them is incorrect for set s={10,20,30,40}


A. Len(s)
B. Sum(s)
C. Print(s[3])
D. Max(s)
ANSWER: C

9. _____________ datatype represents a group of elements written in the form of several key values pairs.
A. complex
B. byte
C. bytearray
D. dict
ANSWER: D

10. 0c or 0C in the beginning of a number represents a ______________ literal.


A. Octal
B. Decimal
C. Binary
D. Hexadecimal
ANSWER: A

11. 0b or 0B in the beginning of a number represents a ______________ literal.


A. Octal
B. Decimal
C. Binary
D. Hexadecimal
ANSWER: C

12. Constants should be written in _______ case


A. lower case
B. First character in capitals
C. Upper case
D. Any case
ANSWER: C

13. The elements of ___________type can be modified.


A. Tuple
B. Range
C. Byte
D. List
ANSWER: D

14. Which of the following is Python prompt?


A. #
B. >>
C. <<
D. >>>
ANSWER: D

15. What is output of 3*2**2?


A. 15
B. 12
C. 18
D. 36
ANSWER: B

16. When there are multiple words in a construct, they should be given with _________
A. Dot (.)
B. Hyphen (-)
C. Underscore (_)
D. Comma (,)
ANSWER: C

17. Triple double quotes or triple single quotes at the beginning and end of the block are used for
___________
A. Strings
B. Constants
C. Multiline comments
D. characters
ANSWER: C

18. ____________ is not a sequence in python.


A. Bytes
B. Tuple
C. Complex
D. Range
ANSWER: C

19. ___________ represents group of elements or items.


A. Complex
B. Sequence
C. Bool
D. Int
ANSWER: B

20. Which of the following is not a numeric type in python?


A. Int
B. Float
C. Complex
D. all the above
ANSWER: C

21. Module names should be written in __________


A. Lower case
B. Upper case
C. Either upper or lower case
D. Starting character alone in uppercase
ANSWER: A
22. Program code making use of a given module is called a ______ of the module.
A. Client
B. Docstring
C. Interface
D. Modularity
ANSWER: A

23. PVM stands for ________


A. Process virtual machine
B. Program virtual machine
C. Python virtual mechanism
D. Python virtual machine
ANSWER: D

24. What will be the output of the following Python code? x = ['ab', 'cd'] for i in x: i.upper() print(x)
A. ['ab', 'cd']
B. ['AB', 'CD']
C. [None, None]
D. none of the mentioned
ANSWER: A

25. Which one of the following has the highest precedence in the expression?
A. Exponential
B. Parentheses
C. Addition
D. Multiplication
ANSWER: B

26. Which one of the following has the same precedence level?
A. Multiplication, Division and Addition
B. Multiplication, Division, Addition and Subtraction
C. Addition and Multiplication
D. Addition and Subtraction
ANSWER: D

27. In order to store values in terms of key and value, which ore data type is used?
A. list
B. tuple
C. class
D. dictionary
ANSWER: D

28. Which of these in not a core data type?


A. Lists
B. Dictionary
C. Tuples
D. Class
ANSWER: D

29. Given a function that does not return any value, What value is thrown by default when executed in shell.
A. int
B. bool
C. void
D. none
ANSWER: D

30. What will be the output of the following Python code? >>>str="hello" >>>str[:2]
A. he
B. lo
C. olleh
D. hello
ANSWER: A

31. Which is the function used to display the datatype?


A. int()
B. type()
C. str()
D. datatype()
ANSWER: B

32. __________________ are the strings written inside triple quotes.


A. null string
B. Dstring
C. Docstrings
D. DistStrings
ANSWER: C

33. Single line comments in python is ______________.


A. ' '
B. " "
C. #
D. >>>
ANSWER: C

34. _______________ is used to allocate memory for objects.


A. Memory manager
B. Storage manager
C. Garbage collector
D. alloc()
ANSWER: A

35. Py_compile module converts python source file into _______________ file.
A. .py
B. .pyc
C. .pc
D. .xpy
ANSWER: B

36. __________ module displays the byte code instruction in human readable format.
A. Dis
B. Pandas
C. Xlrd
D. py
ANSWER: A

37. _____________ package is useful to analyze data.


A. Dis
B. Pandas
C. Xlrd
D. py
ANSWER: B

38. ________________ package is useful to extract data from excel spreadsheet file.
A. Dis
B. Pandas
C. Xlrd
D. py
ANSWER: C

39. Pypy is a just in time compiler used to ________________ execution of the python program.
A. reduce
B. elongate
C. bring down
D. Speed up
ANSWER: D

40. Which one of these is floor division?


A. /
B. //
C. %
D. none of the above
ANSWER: B

41. Which is the correct operator for power(xy)?


A. x^y
B. x**y
C. x^^y
D. none of the above
ANSWER: B

42. Which of the following will run without errors?


A. round(45.8)
B. round(6352.898,2,5)
C. round(7463.123,2,1)
D. round()
ANSWER: A

43. What data type is the object below? L=[100,203, 'hello',10]


A. Dict
B. List
C. Docstring
D. Complex
ANSWER: B

44. What is the output of the following code : Print (15 // 2)


A. 7.5
B. 7
C. error
D. 0
ANSWER: B

45. Operators with the same precedence are evaluated in which manner?
A. Cannot predict
B. Right to Left
C. Left to Right
D. None of the mentioned
ANSWER: C

46. Which is the membership operator used for testing if an element is present in a sequence or not?
A. like, unlike
B. is, is not
C. ismember
D. in, not in
ANSWER: D

47. ____________ is used for finding the identification number of an object.


A. id()
B. identifier()
C. identity()
D. ident()
ANSWER: A

48. nan is a __________ in math module


A. operator
B. constant
C. function
D. class
ANSWER: B

49. Command line arguments are stored in _______________ by default.


A. function
B. var list
C. argv list
D. argc list
ANSWER: C

50. Which of the following is used to accept input from keyboard?


A. scanf()
B. stream()
C. get()
D. input()
ANSWER: D

51. What is the return type of function id?


A. int
B. float
C. bool
D. dict
ANSWER: A

52. 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
ANSWER: D
53. What are the two main types of functions?
A. Custom function
B. Built-in function and User defined function
C. User function
D. System function
ANSWER: B

54. Where is function defined?


A. Module
B. Class
C. Another function
D. All of the mentioned
ANSWER: D

55. What is called when a function is defined inside a class?


A. Module
B. Class
C. Another function
D. Method
ANSWER: D

56. Which of the following is the use of id() function in python?


A. Id returns the identity of the object
B. Every object does not have a unique id
C. All of the mentioned
D. None of the mentioned
ANSWER: A

57. Which of the following refers to mathematical function?


A. sqrt
B. add
C. rhombus
D. delete
ANSWER: A

58. What will be the output of the following Python code? Â def cube(x): return x *x*x x = cube(3) print x
A. 9
B. 6
C. 27
D. 36
ANSWER: C

59. Python supports the creation of anonymous functions at runtime, using a construct called __________
A. lambda
B. pi
C. none
D. all of the above
ANSWER: A

60. What will be the output of the following Python code? def f(x, y, z): return x + y + z f(2, 30, 400)
A. 433
B. 432
C. 431
D. 430
ANSWER: B

61. Which of the following functions is a built-in function in python?


A. seed()
B. sqrt()
C. add()
D. print()
ANSWER: D

62. What will be the output of the following Python expression? Â round(4.576)
A. 4
B. 3
C. 5
D. 6
ANSWER: C

63. What will be the output of the following Python function? all([2,4,0,6])
A. True
B. error
C. false
D. 0
ANSWER: C

64. What will be the output of the following Python expression? round(4.5676,2)?
A. 4.5
B. 5
C. 4.56
D. 4.57
ANSWER: D

65. What will be the output of the following Python function? sum(2,4,6) sum([1,2,3])
A. Error, 6
B. Error, 17
C. Error, 12
D. Error, 20
ANSWER: A

66. What will be the output of the following Python function? complex(1+2j)
A. 1
B. 2
C. 1+2j
D. 2+1j
ANSWER: C

67. What is the output of the function complex()?


A. 0j
B. 0
C. 1
D. 0+0j
ANSWER: A

68. Which of the following functions accepts only integers as arguments?


A. ord()
B. min()
C. max()
D. chr()
ANSWER: D

69. Which of the following functions will not result in an error when no arguments are passed to it?
A. float()
B. all()
C. div()
D. divall()
ANSWER: A

70. What will be the output of the following Python function? hex(15)
A. 0Xf
B. 0xf
C. 1Xf
D. 1xf
ANSWER: B

71. Which of the following functions does not throw an error?


A. ord()
B. ord(" ")
C. ord( '')
D. ord(())
ANSWER: C

72. What will be the output of the following Python function? len(["hello",2, 4, 6])
A. 4
B. 5
C. 6
D. 7
ANSWER: A

73. Which is the most appropriate definition for recursion?


A. A function that calls itself
B. A function execution instance that calls another execution instance of the same function
C. A class method that calls another class method
D. An in-built method that is automatically called
ANSWER: B

74. Which of these is false about recursion?


A. Recursive function can be replaced by a non-recursive function
B. Recursive functions usually take more memory space than non-recursive function
C. Recursive functions run faster than non-recursive function
D. Recursion makes programs easier to understand
ANSWER: C

75. What is tail recursion?


A. A recursive function that has two base cases
B. A function where the recursive functions leads to an infinite loop
C. A recursive function where the function does not return anything and just prints the values
D. A function where the recursive call is the last thing executed by the function
ANSWER: D
76. Which of these is not true about recursion?
A. Making the code look clean
B. A complex task can be broken into sub-problems
C. Recursive calls take up less memory
D. Sequence generation is easier than a nested iteration
ANSWER: C

77. Which of the following commands will create a list?


A. list1 = list()
B. list1 = []
C. list1 = list([1, 2, 3])
D. all of the mentioned
ANSWER: D

78. Suppose list1 is [2445,133,12454,123], what is max(list1)?


A. 2445
B. 1445
C. 2444
D. 2222
ANSWER: A

79. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)?


A. 1
B. 2
C. 3
D. 4
ANSWER: A

80. Suppose list1 is [1, 5, 9], what is sum(list1)?


A. 1
B. 5
C. 9
D. 15
ANSWER: D

81. To shuffle the list(say list1) what function do we use?


A. list1.shuffle()
B. shuffle(list1)
C. random.shuffle(list1)
D. rrandom.shuffleList(list1)
ANSWER: C

82. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?
A. print(list1[0])
B. print(list1[:2])
C. print(list1[:-2])
D. all of the mentioned
ANSWER: D

83. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
A. Error
B. None
C. 25
D. 2
ANSWER: C

84. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
A. [2, 33, 222, 14]
B. [ 33, 222, 14]
C. [2, 33, 14]
D. [2, 33, 222, 214]
ANSWER: A

85. Suppose list1 is [1, 3, 2], What is list1 *2


A. [2,6,4]
B. [12,16,14]
C. [22,26,24]
D. [32,36,34]
ANSWER: A

86. To add a new element to a list we use which command?


A. list1.add(5)
B. list1.append(5)
C. list1.addLast(5)
D. list1.addEnd(5)
ANSWER: B

87. To insert 5 to the third position in list1, we use which command?


A. list1.insert(3, 5)
B. list1.insert(3, 5)
C. list1.insert(3, 5,1)
D. list2.insert(3, 5)
ANSWER: B

88. Suppose list1 is [3, 4, 5, 20, 5], what is list1.index(5)?


A. 0
B. 1
C. 4
D. 2
ANSWER: D

89. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()?
A. [3, 1, 25, 5, 20, 4, 3]
B. [3, 1, 5, 20, 5, 4, 3]
C. [3, 25, 5, 20, 5, 4, 3]
D. [3, 1, 25, 5, 20, 5, 4, 3]
ANSWER: D

90. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1)?
A. [3, 5, 20, 5, 25, 1, 4,3]
B. [3, 5, 20,4, 5, 25, 1, 3]
C. [3, 5, 20, 5, 25, 1, 3]
D. [3,4, 5, 20, 5, 25, 1, 3]
ANSWER: C

91. 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")
ANSWER: B

92. To read two characters from a file object infile, we use ____________
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
ANSWER: A

93. To read the next line of the file from a file object infile, we use ____________
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
ANSWER: C

94. The readlines() method returns ____________


A. str
B. a list of lines
C. a list of single characters
D. a list of integers
ANSWER: B

95. Which of the following functions does not accept any argument?
A. re.purge
B. re.compile
C. re.findall
D. re.match
ANSWER: A

96. What will be the output of the following Python code? #generator def f(x): yield x+1 g=f(8) print(next(g))
A. 9
B. 8
C. 7
D. 6
ANSWER: A

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


A. zero
B. one
C. more than zero
D. more than one
ANSWER: C

98. When will the else part of try-except-else be executed?


A. always
B. when an exception occurs
C. when no exception occurs
D. when an exception occurs in to except block
ANSWER: C

99. 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
ANSWER: D

100. In the following options which are python libraries which are used for data analysis and scientific
computations
A. Numpy
B. Scipy
C. Pandas
D. all the above
ANSWER: D

101. How are keyword arguments specified in the function heading?


A. one star followed by a valid identifier
B. one underscore followed by a valid identifier
C. two stars followed by a valid identifier
D. two underscores followed by a valid identifier
ANSWER: C

102. What is the type of sys.argv?


A. set
B. list
C. tuple
D. string
ANSWER: D

103. Which of the following statements is used to create an empty set?


A. set()
B. ()
C. {}
D. []
ANSWER: A

104. Which of the following is required to create a new instance of the class?
A. class
B. method
C. constructor
D. values
ANSWER: C

105. Suppose t = (1, 2, 4, 3), which of the following is incorrect


A. t[3]=45
B. print(max(t))
C. print(len(t))
D. print(sum(t))
ANSWER: A

106. 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() does not exist for dictionary
ANSWER: A

107. 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 are not ordered
D. Dictionaries are mutable
ANSWER: B

108. 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()
ANSWER: B

109. Which of the following statements create a dictionary?


A. d = {}
B. d = {"john":40, "peter":45}
C. d = {40:"john", 45:"peter"}
D. All of the mentioned
ANSWER: D

110. To which of the following the "in" operator can be used to check if an item is in it?
A. Lists
B. Dictionary
C. Set
D. All of the mentioned
ANSWER: D

111. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?
A. print(list1[0])
B. print(list1[:2])
C. print(list1[:-2])
D. all of the mentioned
ANSWER: D

112. To shuffle the list(say list1) what function do we use?


A. list1.shuffle()
B. shuffle(list1)
C. random.shuffle(list1)
D. random.shuffleList(list1)
ANSWER: C

113. Which of the following commands will create a list?


A. list1 = list()
B. list1 = []
C. list1 = list([1, 2, 3])
D. all of the mentioned
ANSWER: D

114. What type of data is: a=[(1,1),(2,4),(3,9)]?


A. Array of tuples
B. List of tuples
C. Tuples of lists
D. Invalid type
ANSWER: B

115. What is the data type of (1)?


A. Tuple
B. Integer
C. List
D. Both tuple and integer
ANSWER: B

116. Suppose t = (1, 2, 4, 3), which of the following is incorrect?


A. print(t[3])
B. t[3]
C. print(max(t))
D. print(len(t))
ANSWER: B

117. Which of the following is a Python tuple?


A. [1, 2, 3]
B. (1, 2, 3)
C. "1, 2, 3"
D. {}
ANSWER: B

118. Where are the arguments received from the command line stored?
A. sys.argv
B. os.argv
C. argv
D. none of the mentioned
ANSWER: A

119. What is the value stored in sys.argv[0]?


A. null
B. you cannot access it
C. the program's name
D. the first argument
ANSWER: C

120. Which module in the python standard library parses options received from the command line?
A. getopt()
B. main
C. module
D. os
ANSWER: A

121. How are variable length arguments specified in the function heading?
A. one star followed by a valid identifier
B. one underscore followed by a valid identifier
C. two stars followed by a valid identifier
D. two underscores followed by a valid identifier
ANSWER: A
122. Which of the following functions will not result in an error when no arguments are passed to it?
A. min()
B. divmod()
C. all()
D. float()
ANSWER: D

123. What will be the output of the following Python function any([2>8, 4>2, 1>2])?
A. Error
B. True
C. False
D. 4>2
ANSWER: B

124. What is Instantiation in terms of OOP terminology?


A. Deleting an instance of class
B. Modifying an instance of class
C. Copying an instance of class
D. Creating an instance of class
ANSWER: D

125. What will be the value of X in the following Python expression? X = 2+9*((3*12)-8)/10
A. 27.6
B. 27.7
C. 22.2
D. 27.2
ANSWER: D

126. Which among the following list of operators has the highest precedence? +, -, **, %, /, <<, >>, |
A. **
B. |
C. <<
D. >>
ANSWER: A

127. What will be the value of the following Python expression? float(4+int(2.39)%2)
A. 5.0
B. 5
C. 4.0
D. 4
ANSWER: D

128. Which of the following expressions is an example of type conversion?


A. 4.0 + float(3)
B. 5.3 + 6.3
C. 5.0 + 3
D. 3 + 7
ANSWER: A

129. What will be the value of the following Python expression? 4+2**5//10
A. 3
B. 7
C. 77
D. 0
ANSWER: B

130. What will be the output of the following Python code snippet if x=1? x<<2
A. 8
B. 1
C. 2
D. 4
ANSWER: D

131. What will be the output of the following Python expression?bin(29)


A. '0b10111'
B. '0b11101'
C. '0b11101'
D. '0b01111'
ANSWER: C

132. What will be the output of the following Python expression? int(1011)?
A. 1011
B. 10
C. 1101
D. 1111
ANSWER: A

133. To find the decimal value of 1111, that is 15, we can use the function:
A. int(1111,10)
B. int('1111',10)
C. int(1111,2)
D. int('1111',2)
ANSWER: D

134. Which of the following represents the bitwise XOR operator?


A. |
B. *
C. &
D. ^
ANSWER: D

135. What will be the output of the following Python expression? 0x35 | 0x75
A. 115
B. 116
C. 117
D. 118
ANSWER: C

136. Bitwise _________ gives 1 if either of the bits is 1 and 0 when both of the bits are 1.
A. OR
B. AND
C. XOR
D. NOT
ANSWER: C

137. Select the reserved keyword in python


A. else
B. import
C. raise
D. all the above
ANSWER: D

138. Which keyword is used to define methods in Python?


A. function
B. method
C. def
D. all of these
ANSWER: C

139. Which predefined Python function is used to find length of string?


A. length()
B. len()
C. stringlen()
D. stringlength()
ANSWER: B

140. The format function, when applied on a string returns :


A. int
B. bool
C. float
D. str
ANSWER: D

141. What is the maximum possible length of an identifier?


A. 66
B. 55
C. 77
D. none of the above
ANSWER: D

142. The expression a{5} will match _____________ characters with the previous regular expression.
A. more than 5 elements
B. less than 5 elements
C. exactly 5 elements
D. none
ANSWER: C

143. What will be the output of the following Python code?print("xyyzxyzxzxyy".count('yy', 2)


A. 2
B. 1
C. 0
D. -1
ANSWER: B

144. What will be the output of the following Python code? >>>a={3,4,5} >>>a.update([1,2,3]) >>> a
A. {1.2.3.4.5}
B. {3,4,5}
C. {1,2,3}
D. Error
ANSWER: A

145. What will be the output of the following Python code? import time time.asctime()
A. Current date only
B. UTC time
C. Current date and time
D. Current time only
ANSWER: C

146. What will be the output of the following Python code, if the time module has already been imported? 4 +
'3'
A. NameError
B. IndexError
C. ValueError
D. TypeError
ANSWER: D

147. What will be the output of the following Python code? x = (i for i in range(3)) for i in x: print(i)
A. 0 1 2
B. error
C. 0 1 2 0 1 2
D. none of the mentioned
ANSWER: A

148. append() is used for ________________ elements in an array


A. any number
B. 1
C. 2
D. not a function
ANSWER: B

149. Which is the function used to remove the given item as parameter?
A. pop()
B. remove()
C. del()
D. delete()
ANSWER: B

150. Which is the type code that has to given to given for array of double type?
A. d
B. D
C. L
D. l
ANSWER: A

Staff Name
Srividhya R .

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy