Python DCE3201 New
Python DCE3201 New
________________________________________________________________
Question Bank
A. 1972
B. 1995
C. 1989
D. 1981
A. .p
B. .py
C. .python
D. None of the above
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
A. Parenthesis
B. Indentation
C. Curly braces
D. None of the above
A. *
B. @
C. #
D. !
A. package
B. module
C. directory
D. None of the above
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:
elif True:
else:
A. inside if block
B. inside elif block
C. inside else block
D. Error
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
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
A. 32
B. 33
C. 31
D. 30
A. 32
B. 31
C. 63
D. None of the above
A. Lowercase
B. Uppercase
C. Both uppercase & Lowercase
D. None of the above
A. var@
B. 32var
C. class
D. abc_a_c
21. Why are local variable names beginning with an underscore discouraged?
A. >=
B. <=
C. =
D. !=
23. What is the output of the following program : print((1, 2) + (3, 4))
A. set
B. int
C. str
D. tupl
A. list
B. set
C. int
D. dict
A. in
B. is
C. assert
D. All of the above
A. 2
B. 2.5
C. 2.0
D. Error
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
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
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
40. Which one of the following has the highest precedence in the expression?
a) Exponential
b) Addition
c) Multiplication
d) Parentheses
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
hello-how-are-you
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) **
x = int(43.55+2/2)
a)43
b)44
c)22
d) 23
2+4.00, 2**4.0
a) (6.0, 16.0)
b) (6.00, 16.00)
c) (6, 16)
d) (6.00, 16.0)
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
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
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
int(1011)?
a) 1011
b) 11
c) 13
d) 1101
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
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
i=2
while(i>0):
i=i-1
A. 2
B. 3
C. 1
D. 0
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
A. Yes
B. No
C. if/else not used in python
D. None of the above
A. if a = b:
B. if a == b:
C. if a === c:
D. if a == b
A. True
B. False
C. Python has switch statement but we can not use it.
D. None of the above
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
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 …
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
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
True = False
while True:
print(True)
break
a) True
b) False
c) None
d) none of the mentioned
x = 123
for i in x:
print(i)
a) 1 2 3
b) 123
c) error
d) none of the mentioned
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
a) 2 b)4 c) 7 d)6
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
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
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?
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
a, b = 12, 5
if a + b:
print('True')
else:
print('False')
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
1. >>>print('new' 'line')
a) Error
b) Output equivalent to print ‘new\nline’
c) newline
d) new line
class Truth:
pass
x=Truth()
bool(x)
a) pass
b) true
c) false
d) error
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. Keyword
B. Variable argument count
C. Positional
D. None of these
var2=9
var1=3
function1(10,12)
A. 5 7
B. 3 9
C. 10 12
D. Error
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
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)
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
str1="python"
A. print(str1[2])
B. str1[1]="x"
C. print(str1[0:9])
D. Both (b) and (c)
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
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
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.
str1="Stack of books"
print(len(str1))
A. 13
B. 14
C. 15
D. 16
1. >>>"a"+"bc"
a) a
b) bc
c) bca
d) abc
1. >>>"abcd"[2:]
a) a
b) ab
c) cd
d) dc
1. >>>str1="helloworld"
2. >>>str1[::-1]
a) dlrowolleh
b) hello
c) world
d) helloworld
round(4.576)
a) 4.5
b) 5
c) 4
d) 4.6
all([2,4,0,6])
a) Error
b) True
c) False
d) 0
round(4.5676,2)?
a) 4.5
b) 4.6
c) 4.57
d) 4.56
143. Only problems that are recursively defined can be solved using recursion.
a) True
b) False
a) cant solved
b) none of the above
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()