0% found this document useful (0 votes)
8 views

Python DCE3201 New

This document is a question bank for a Python programming course at Dr. Babasaheb Ambedkar Technological University. It contains multiple-choice questions covering various topics such as Python syntax, data types, operators, and control structures. The questions are designed to assess students' understanding of Python programming concepts.

Uploaded by

sarojjangid117
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Python DCE3201 New

This document is a question bank for a Python programming course at Dr. Babasaheb Ambedkar Technological University. It contains multiple-choice questions covering various topics such as Python syntax, data types, operators, and control structures. The questions are designed to assess students' understanding of Python programming concepts.

Uploaded by

sarojjangid117
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Dr.

Babasaheb Ambedkar Technological Universitiy’s

Institute of Petrochemical Engineering, Lonere

Department of Information technology

Subject: Programming In python Course code: DCE3201

Semester: VI Sub Incharge: Ms. Ovhal S.B.

________________________________________________________________
Question Bank

Unit I: Introduction to Python Programming

1. Python was developed by

A. Guido van Rossum


B. James Gosling
C. Dennis Ritchie
D. Bjarne Stroustrup

2. Python was developed in which year?

A. 1972
B. 1995
C. 1989
D. 1981

3. What is the extension of python file?

A. .p
B. .py
C. .python
D. None of the above

4. Python is Object Oriented Programming Language.

A. True
B. False
C. Neither true nor false
D. None of the above
5. Python 3.0 is released in which year?

A. 2000
B. 2008
C. 2011
D. 2016

6. Which of the following statements is true?

A. Python is a high level programming language.


B. Python is an interpreted language.
C. Python is an object-oriented language
D. All of the above

7. What is used to define a block of code in Python?

A. Parenthesis
B. Indentation
C. Curly braces
D. None of the above

8. By the use of which character, single line is made comment in Python?

A. *
B. @
C. #
D. !

9. What is a python file with .py extension called?

A. package
B. module
C. directory
D. None of the above

10. What will be the output of the following program on execution?

a=0

b=5

x=(a&b)|(a&a)|(a|b)

print("x")

A. 1
B. 5
C. 0
D. None of the above
11. What will be the output of the following program on execution?

if False:

print ("inside if block")

elif True:

print ("inside elif block")

else:

print ("inside else block")

A. inside if block
B. inside elif block
C. inside else block
D. Error

12. Which of the following is incorrect variable name in Python?

A. variable_1
B. variable1
C. 1variable
D. _variable

13. Which one of the following is correct way of declaring and initialising a variable, x with
value 5?

A. int x
x=5
B. int x=5
C. x=5
D. declare x=5

14. Which of the following is incorrect regarding variables in Python?

A. Variable names in Python cannot start with number. However, it can contain number in
any other position of variable name.
B. Variable names can start with an underscore.
C. Data type of variable names should not be declared
D. None of the above
15. Which of the following will give error?

A. a=b=c=1
B. a,b,c=1
C. a,b,c=1, “python―, 1.5
D. None of the above

16. How many keywords are there in python 3.7?

A. 32
B. 33
C. 31
D. 30

17. What is the maximum length of an identifier in python?

A. 32
B. 31
C. 63
D. None of the above

18. All keyword in python are in

A. Lowercase
B. Uppercase
C. Both uppercase & Lowercase
D. None of the above

19. Which of the following statment is False?

A. Variable names can be arbitrarily long.


B. They can contain both letters and numbers.
C. Variable name can begin with underscore.
D. Variable name can begin with number.

20. Which of the following is a valid variable?

A. var@
B. 32var
C. class
D. abc_a_c

21. Why are local variable names beginning with an underscore discouraged?

A. they confuse the interpreter


B. they are used to indicate a private variables of a class
C. they are used to indicate global variables
D. they slow down execution
22. Which of the following is not a relational opeartor in Python?

A. >=
B. <=
C. =
D. !=
23. What is the output of the following program : print((1, 2) + (3, 4))

A. (1, 2), (3, 4)


B. (4, 6)
C. (1, 2, 3, 4)
D. Invalid Syntax

24. Which one of the following is mutable data type?

A. set
B. int
C. str
D. tupl

25. Which one of the following is immutable data type?

A. list
B. set
C. int
D. dict

26. Which of these are keyword?

A. in
B. is
C. assert
D. All of the above

27. What is the output of the following code : print 5//2

A. 2
B. 2.5
C. 2.0
D. Error

28. Is Python case sensitive when dealing with identifiers?

a) yes
b) no
c) machine dependent
d) none of the mentioned
29. Which of the following is invalid?

a) _a = 1
b) __a = 1
c) __str__ = 1
d) none of the mentioned

30. Which of the following is true for variable names in Python?


a) unlimited length
b) all private members must have leading and trailing underscores
c) underscore and ampersand are the only two special characters allowed
d) none of the mentioned

31. Which of the following is an invalid statement?


a) abc = 1,000,000
b) a b c = 1000 2000 3000
c) a,b,c = 1000, 2000, 3000
d) a_b_c = 1,000,000

32. Which of the following cannot be a variable?


a) __init__
b) in
c) it
d) on

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


a) X^y
b) X**y
c) X^^y
d) None of the mentioned

34. Which one of these is floor division?


a) /
b) //
c) %
d) None of the mentioned

35. What is the order of precedence in python?


i) Parentheses
ii) Exponential
iii) Multiplication
iv) Division
v) Addition
vi) Subtraction

a) i,ii,iii,iv,v,vi
b) ii,i,iii,iv,v,vi
c) ii,i,iv,iii,v,vi
d) i,ii,iii,iv,vi,v
36. What is the answer to this expression, 22 % 3 is?
a) 7
b) 1
c) 0
d) 5

37. Mathematical operations can be performed on a string.


a) True
b) False
c) True in some cases
d) None of the above

38. 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

39. What is the output of this expression, 3*1**3?


a) 27
b) 9
c) 3
d) 1

40. Which one of the following has the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses

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


a) Lists
b) Dictionary
c) Tuples
d) Class

42. What is the return type of function id?


a) int
b) float
c) bool
d) dict

43. What error occurs when you execute the following Python code snippet?
apple = mango

a)SyntaxError
b)NameError
c)ValueError
d) TypeError
44. Which of the following results in a SyntaxError?
a) ‘”Once upon a time…”, she said.’
b) “He said, ‘Yes!'”
c) ‘3\’
d) ”’That’s okay”’

45. What is the average value of the following Python code snippet?

1. >>>grade1 = 80
2. >>>grade2 = 90
3. >>>average = (grade1 + grade2) / 2
a)85.0
b)85.1
c)95.0
d) 95.1

46. Select all options that print.

hello-how-are-you

a) print(‘hello’, ‘how’, ‘are’, ‘you’)


b) print(‘hello’, ‘how’, ‘are’, ‘you’ + ‘-‘ * 4)
c) print(‘hello-‘ + ‘how-are-you’)
d) print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘you’)

47. What is the output of print 0.1 + 0.2 == 0.3?


a) True
b) False
c) Machine dependent
d) Error

48. Which of the following is not a complex number?


a) k = 2 + 3j
b) k = complex(2, 3)
c) k = 2 + 3l
d) k = 2 + 3J

49. Evaluate the expression given below if A = 16 and B = 15.

A % B // A
a)0.0
b)0
c)1.0
d) 1
50. Which of the following operators has its associativity from right to left?
a) +
b) //
c) %
d) **

51. What will be the value of x in the following Python expression?

x = int(43.55+2/2)
a)43
b)44
c)22
d) 23

52. What is the value of the following expression?

2+4.00, 2**4.0
a) (6.0, 16.0)
b) (6.00, 16.00)
c) (6, 16)
d) (6.00, 16.0)

53. Which of the following is the truncation division operator?


a) /
b) %
c) //
d) |

54. What are the values of the following Python expressions?

2**(3**2)
(2**3)**2
2**3**2
a)64,512,64
b)64, 64, 64
c) 512, 512, 512
d) 512, 64, 512

55. What is the value of the following expression?

8/4/2, 8/(4/2)
a) (1.0, 4.0)
b) (1.0, 1.0)
c) (4.0. 1.0)
d) (4.0, 4.0)
56. What will be the output of the following Python code snippet if x=1?

x<<2
a) 8
b) 1
c) 2
d) 4

57. What will be the output of the following Python expression?

bin(29)
a) ‘0b10111’
b) ‘0b11101’
c) ‘0b11111’
d) ‘0b11011’

58. What will be the value of x in the following Python expression, if the result of that
expression is 2?

x>>2
a) 8
b) 4
c) 2
d) 1

59. What will be the output of the following Python expression?

int(1011)?
a) 1011
b) 11
c) 13
d) 1101

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


a) &
b) ^
c) |
d) !

61. The one’s complement of 110010101 is:


a) 001101010
b) 110010101
c) 001101011
d) 110010100
62. 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

63. Which of the following expressions can be used to multiply a given number ‘a’ by 4?
a) a<<2
b) a<<4
c) a>>2
d) a>>4

64. What is the two’s complement of -44?


a) 1011011
b) 11010100
c) 11101011
d) 10110011

65. What will be the output of the following Python expression?

4^12
a) 2
b) 4
c) 8
d) 12
Unit II: Decision Statements
66. Which of the following is not used as loop in Python?

A. for loop
B. while loop
C. do-while loop
D. None of the above

67. Which of the following is False regarding loops in Python?

A. Loops are used to perform certain tasks repeatedly.


B. While loop is used when multiple statements are to executed repeatedly until the given
condition becomes False
C. While loop is used when multiple statements are to executed repeatedly until the given
condition becomes True.
D. for loop can be used to iterate through the elements of lists.

68. Which of the following is True regarding loops in Python?

A. Loops should be ended with keyword "end".


B. No loop can be used to iterate through the elements of strings.
C. Keyword "break" can be used to bring control out of the current loop.
D. Keyword "continue" is used to continue with the remaining statements inside the loop.

69. How many times will the loop run?

i=2

while(i>0):

i=i-1

A. 2
B. 3
C. 1
D. 0

70. Which one of the following is a valid Python if statement :

A. if a>=2 :
B. if (a >= 2)
C. if (a => 22)
D. if a >= 22
71. What keyword would you use to add an alternative condition to an if statement?

A. else if
B. elseif
C. elif
D. None of the above

72. Can we write if/else into one line in python?

A. Yes
B. No
C. if/else not used in python
D. None of the above

73. In a Python program, a control structure:

A. Defines program-specific data structures


B. Directs the order of execution of the statements in the program
C. Dictates what happens before the program starts and after it terminates
D. None of the above

74. Which statement will check if a is equal to b?

A. if a = b:
B. if a == b:
C. if a === c:
D. if a == b

75. Does python have switch case statement?

A. True
B. False
C. Python has switch statement but we can not use it.
D. None of the above

76. 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
77. What will be the output of the following Python code?

i=1
while True:
if i%3 == 0:
break
print(i)

i+=1
a) 1 2
b) 1 2 3
c) error
d) none of the mentioned

78. What will be the output of the following Python code?

i=1
while True:
if i%2 == 0:
break
print(i)
i += 2
a) 1
b) 1 2
c) 1 2 3 4 5 6 …
d) 1 3 5 7 9 11 …

79. What will be the output of the following Python code?

i=2
while True:
if i%3 == 0:
break
print(i)
i += 2
a) 2 4 6 8 10 …
b) 2 4
c) 2 3
d) error

80. What will be the output of the following Python code?

i=1
while False:
if i%2 == 0:
break
print(i)
i += 2
a) 1
b) 1 3 5 7 …
c) 1 2 3 4 …
d) none of the mentioned

81. What will be the output of the following Python code?

True = False
while True:
print(True)
break
a) True
b) False
c) None
d) none of the mentioned

82. What will be the output of the following Python code?

x = 123
for i in x:
print(i)
a) 1 2 3
b) 123
c) error
d) none of the mentioned

83. What will be the output of the following Python code?

d = {0: 'a', 1: 'b', 2: 'c'}


for i in d:
print(i)
a) 0 1 2
b) a b c
c) 0 a 1 b 2 c
d) none of the mentioned

84. What will be the output of the following Python code?

x = 'abcd'
for i in x:
print(i)
x.upper()
a) a B C D
b) a b c d
c) A B C D
d) error
85. What will be the output of the following Python code?

x = 'abcd'
for i in range(len(x)):
print(i)
a) a b c d
b) 0 1 2 3
c) error
d) 1 2 3 4

86. What is the result of x? when, x=(2+2)//2-1*(2-1)+6

a) 2 b)4 c) 7 d)6

87. What will be the output of the following Python code?

for i in range(10):
if i == 5:
break
else:
print(i)
else:
print("Here")
a) 0 1 2 3 4 Here
b) 0 1 2 3 4 5 Here
c) 0 1 2 3 4
d) 1 2 3 4 5

88. What will be the output of the following Python code?

for i in range(5):
if i == 5:
break
else:
print(i)
else:
print("Here")
a) 0 1 2 3 4 Here
b) 0 1 2 3 4 5 Here
c) 0 1 2 3 4
d) 1 2 3 4 5

89. What will be the output of the following Python code snippet?

['hello', 'morning'][bool('')]
a) error
b) no output
c) hello
d) morning

90. What will be the output of the following Python code?

class Truth:
pass
x=Truth()
bool(x)
a) pass
b) true
c) false
d) error

91. Which of the following Boolean expressions is not logically equivalent to the other three?
a) not(-6<0 or-6>10)
b) -6>=0 and -6<=10
c) not(-6<10 or-6==10)
d) not(-6>10 or-6==10)

92. What will be the output of the following Python code snippet?

not(10<20) and not(10>30)


a) True
b) False
c) Error
d) No output

93. What will be the output of the following Python code?

for i in range(int(2.0)):
print(i)
a) 0.0 1.0
b) 0 1
c) error
d) none of the mentioned

94. What is the output of the following for loop and range() function

for num in range(-2,-5,-1):

print(num, end=", ")

a) -2, -1, -3, -4


b) -2, -1, 0, 1, 2, 3,
c) -2, -1, 0
d) -2, -3, -4,

95. What is the output of the following if statement

a, b = 12, 5

if a + b:

print('True')

else:

print('False')

a) True b) false c) cant say d) none of the above

96. What does the following code print to the console?


if "cat" == "dog":
print("prrrr")
else:
print("ruff")
a)prrrr b) ruff c) error d) none of the above

97.What does the following code print to the console?


if 5 > 10:
print("fan")
elif 8 != 9:
print("glass")
else:
print("cream")
a)fan b)glass c)cream d)error

98. What does the following code print to the console?


name = "maria"
if name == "melissa":
print("usa")
elif name == "mary":
print("ireland")
else:
print("colombia")

a)melissa b)Ireland c)colombia d)error

99. What does the following code print to the console?


if 88 > 100:
print("cardio")
a)100 b)88 c)cardio d)nothing is printed on the screen

100. What does the following code print to the console?


if 1:
print("1 is truthy!")
else:
print("???")
a)??? b)1 is truthy! C)error d)none of the above

101. What does the following code print to the console?


if 0:
print("huh?")
else:
print("0 is falsy!")

a) 0 is falsy! b)huh? C)error d)none of the above

102. In Python, how are arguments passed?


A. pass by value
B. pass by reference
C. It gives options to user to choose
D. Both A and B

103. Which among the following are mutable objects in Python?


(i) List
(ii) Integer
(iii) String
(iv) Tuple

A. i only
B. i and ii only
C. iii and iv only
D. iv only

104. In which part of memory does the system stores the parameter and local variables of
funtion call?

A. heap
B. stack
C. Uninitialized data segment
D. None of the above

105. What will be the output of the following Python statement?

1. >>>print('new' 'line')
a) Error
b) Output equivalent to print ‘new\nline’
c) newline
d) new line

106. What will be the output of the following Python code?

print(0xA + 0xB + 0xC)


a) 0xA0xB0xC
b) Error
c) 0x22
d) 33

107. What will be the output of the following Python code?


1. >>>max("what are you")
a) error
b) u
c) t
d) y

108. What will be the output of the following Python code?

class Truth:
pass
x=Truth()
bool(x)
a) pass
b) true
c) false
d) error

109. 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

110. What will be the output of the following Python function?

sum(2,4,6)
sum([1,2,3])
a) Error, 6
b) 12, Error
c) 12, 6
d) Error, Error
Unit III: Functions and String
111. Which of the following is incorrect way of using an argument while defining a function
in Python, where var1 and var2 are two arguments?

A. def fn(var1, var2)


B. def fn(var1, var2=5)
C. def fn(*var1, var2)
D. def fn(var1,*var2)

112. Which of the following is not a type of argument in Python?

A. Keyword
B. Variable argument count
C. Positional
D. None of these

113. What will be the output of the following Python code?

def function1(var1=5, var2=7):

var2=9

var1=3

print (var1, " ", var2)

function1(10,12)

A. 5 7
B. 3 9
C. 10 12
D. Error

114. Which keyword is use for function?

A. define
B. fun
C. def
D. function

115. Which of the following items are present in the function header?

A. function name
B. parameter list
C. return value
D. Both A and B
116. What is called when a function is defined inside a class?

A. class
B. function
C. method
D. module

117. If return statement is not used inside the function, the function will return:

A. None
B. 0
C. Null
D. Arbitary value

118. What is a recursive function?

A. A function that calls other function.


B. A function which calls itself.
C. Both A and B
D. None of the above

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

A. Id() returns the size of object.


B. Id() returns the identity of the object.
C. Both A and B
D. None of the above

120. Which of the following function headers is correct?

A. def fun(a = 2, b = 3, c)
B. def fun(a = 2, b, c = 3)
C. def fun(a, b = 2, c = 3)
D. def fun(a, b, c = 3, d)

121. How is a function declared in Python?

A. def function function_name():


B. declare function function_name():
C. def function_name():
D. declare function_name():

122. Which one of the following is the correct way of calling a function?

A. function_name()
B. call function_name()
C. ret function_name()
D. function function_name()
123. What will be the output of above Python code?

str1="6/4"

print("str1")

A. 1
B. 6/4
C. 1.5
D. str1

124. Which of the following will result in an error?

str1="python"
A. print(str1[2])
B. str1[1]="x"
C. print(str1[0:9])
D. Both (b) and (c)

125. Which of the following is False?

A. String is immutable.
B. capitalize() function in string is used to return a string by converting the whole given
string into uppercase.
C. lower() function in string is used to return a string by converting the whole given string
into lowercase.
D. None of these.
126. What will be the output of below Python code?

str1="Information"

print(str1[2:8])

A. format
B. formatio
C. orma
D. ormat

127. What will be the output of below Python code?

str1="Aplication"

str2=str1.replace('a','A')

print(str2)

A. application
B. Application
C. ApplicAtion
D. applicAtion
128. What will be the output of below Python code?

str1="poWer"

str1.upper()

print(str1)

A. POWER
B. Power
C. power
D. poWer

129. What will the below Python code will return?

If str1="save paper,save plants"

str1.find("save")
A. It returns the first index position of the first occurance of "save" in the given string str1.
B. It returns the last index position of the last occurance of "save" in the given string str1.
C. It returns the last index position of the first occurance of "save" in the given string str1.
D. It returns the first index position of the first occurance of "save" in the given string str1.

130. What will following Python code return?

str1="Stack of books"

print(len(str1))

A. 13
B. 14
C. 15
D. 16

131. What will be the output of the following Python statement?

1. >>>"a"+"bc"
a) a
b) bc
c) bca
d) abc

132. What will be the output of the following Python statement?

1. >>>"abcd"[2:]
a) a
b) ab
c) cd
d) dc

133. What will be the output of the following Python code?

1. >>> str1 = 'hello'


2. >>> str2 = ','
3. >>> str3 = 'world'
4. >>> str1[-1:]
a) olleh
b) hello
c) h
d) o

134. What arithmetic operators cannot be used with strings?


a) +
b) *
c) –
d) All of the mentioned

135. What will be the output of the following Python code?

1. >>>str1="helloworld"
2. >>>str1[::-1]
a) dlrowolleh
b) hello
c) world
d) helloworld

136. What will be the output of the following Python code?

1. >>>example = "snow world"


2. >>>example[3] = 's'
3. >>>print example
a) snow
b) snow world
c) Error
d) snos world

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


a) seed()
b) sqrt()
c) factorial()
d) print()

138. What will be the output of the following Python expression?

round(4.576)
a) 4.5
b) 5
c) 4
d) 4.6

139. The function pow(x,y,z) is evaluated as:


a) (x**y)**z
b) (x**y) / z
c) (x**y) % z
d) (x**y)*z

140. What will be the output of the following Python function?

all([2,4,0,6])
a) Error
b) True
c) False
d) 0

141. What will be the output of the following Python expression?

round(4.5676,2)?
a) 4.5
b) 4.6
c) 4.57
d) 4.56

142. 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

143. Only problems that are recursively defined can be solved using recursion.
a) True
b) False
a) cant solved
b) none of the above

144. 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

145. 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 doesn’t return anything and just prints the values
d) A function where the recursive call is the last thing executed by the function

146. Which of the following statements is false about recursion?


a) Every recursive function must have a base case
b) Infinite recursion can occur if the base case isn’t properly mentioned
c) A recursive function makes the code easier to understand
d) Every recursive function must have a return value

147. Which of the following is the use of function in python?


a) Functions are reusable pieces of programs
b) Functions don’t provide better modularity for your application
c) you can’t also create your own functions
d) All of the mentioned

148. What is a variable defined outside a function referred to as?


a) A static variable
b) A global variable
c) A local variable
d) An automatic variable

149. What is a variable defined inside a function referred to as?


a) A global variable
b) A volatile variable
c) A local variable
d) An automatic variable

150. If a function doesn’t have a return statement, which of the following does the function
return?
a) int
b) null
c) None
d) An exception is thrown without the return statement

151. Suppose there is a list such that: l=[2,3,4]. If we want to print this list in reverse order,
which of the following methods should be used?
a) reverse(l)
b) list(reverse[(l)])
c) reversed(l)
d) list(reversed(l))
152. 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()

153. 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

154. What are the two main types of functions?


a) Custom function
b) Built-in function & User defined function
c) User function
d) System function

155. Where is function defined?


a) Module
b) Class
c) Another function
d) All of the mentioned

You might also like