Java Question Bank
Java Question Bank
What do you call a command-line interpreter which lets you interact with your OS
and execute Python commands and scripts?
A. An editor
B. A console
C. A compiler
D. Jython
2. What is the expected behavior of the following program?
print("Hello!")
A. The program will output ("Hello!") to the screen
B. The program will generate an error message on the screen
C. The program will output Hello! to the screen
D. The program will output "Hello!" to the screen
3. What is the best definition of a script?
A. It’s an error message generated by the interpreter
B. It’s an error message generated by the compiler
C. It’s a text file that contains which make up a Python program
D. It’s a text file that contains sequences of zeroes and ones
4. What is the expected behavior of the following program?
print("Goodbye!")
A. The program will output Goodbye! to the screen
B. The program will generate an error message on the screen
C. The program will output("Goodbye!")
D. The program will output "Goodbye!"
i=0
while i <= 3 :
i += 2
print("+")
a. three
b. zero
c. one
d. two
27. After execution of the following snippet, the sum of the all vals elements will equal
to:
vals = [0, 1, 2]
vals.insert(0, 1)
del vals[1]
a. 3
b. 4
c. 2
d. 5
28. How many hashes(#) will the following snippet send to the console?
for i in range(1):
print("#")
else:
print("#")
a. zero
b. three
c. two
d. one
29. How many hashes(#) will the following snippet send to the console?
var = 0
var += 1
if var % 2 == 0:
continue
print("#")
a. zero
b. three
c. two
d. one
30. What is the output of the following snippet?
print(my_list[my_list(-1)])
a. -2
b. -1
c. 3
d. 1
31. How many stars(#) will the following snippet send to the console?
var = 0
while i <= 5:
i += 1
if vi % 2 == 0:
break
print("*")
a. three
b. two
c. one
d. zero
32. What is the output of the following snippet?
my_list = [1, 2, 3, 4]
print(my_list[-3:-2])
a. [2, 3]
b. [2, 3, 4]
c. []
d. [2]
33. How many hashes(#) will the following snippet send to the console?
var = 1
print("#")
a. two
b. eight
c. four
d. one
34. Take a look at the snippet, and choose the true statements: (Select two answer)
nums = [1, 2, 3]
vals = nums
del vals[1:2]
print(my_list[2][0])
a. 1
b. 2
c. 0
d. the snippet will cause a runtime error
36. What value will be assigned to the x variable?
z = 10
y=0
a. 1
b. 0
c. True
d. False
37. Which of the following sentences are true? (Select two answers)
nums = [1, 2, 3]
vals = nums[-1:-2]
my_list = [1, 2, 3]
for v in range(len(my_list)):
my_list.insert(1, my_list[v])
print(my_list)
a. [1, 2, 3, 1, 2, 3]
b. [1, 2, 3, 3, 2, 1]
c. [1, 1, 1, 1, 2, 3]
d. [3, 2, 1, 1, 2, 3]
39. An operator able to check whether two values are equal is code as:
a. =
b. !=
c. ==
d. ===
40. The second assignment:
vals = [0, 1, 2]
x=1
x = x == x
a. 0
b. 1
c. True
d. False
42. How many elements does the my_list list contain?
a. two
b. three
c. four
d. one
43. Which of the following lines properly starts a function using two parameters, both
with zeroed default values?
def func_1(a):
return a ** a
def func_2(a):
print(func_2(2))
a. will output 2
b. will output 16
c. will output 4
d. is erroneous
46. What code would you insert instead of the comment to obtain the expected output?
Expected output:
Code:
dictionary = {}
dictionary[my_list[i]] = (my_list[i], )
for i in sorted(dictionary.key()):
k = dictionary[i]
a. print(k["0"])
b. print(k['0'])
c. print(k)
d. print(k[0])
47. The following snippet:
print(func(2))
a. is erroneous
b. will output 2
c. will output 4
d. will return None
48. What is the output of thee following snippet?
print(fn(out =2))
a. 2
b. 6
c. 4
d. the snippet is erroneous
49. Assuming that my_tuple is a correctly created tuple, the fact that tuples are immutable
means that the following instruction:
a. can be executed if and only if the tuple contains at least two elements
b. is illegal
c. may be illegal if the tuple contains string
d. is fully correct
50. A function defined in the following way: (Select two answers)
def function(x=0):
return x
def fun(x):
x += 1
return x
x=2
x = fun(x + 1)
print(x)
a. 3
b. 5
c. the code erroneous
d. 4
52. What is the output of the following snippet?
def my_list(my_list):
del my_list[3]
my_list[3] = 'ram'
print(my_list(my_list))
def f(x):
if x == 0:
return 0
return x + f(x - 1)
print(f(3))
a. 6
b. the code is erroneous
c. 1
d. 3
54. What is the output of the following snippet?
tup = (1, 2, 4, 8)
tup = tup[1:-1]
tup = tup[0]
print(tup)
def fun(x):
global y
y=x*x
return y
fun(2)
print(y)
v = dictionary['one']
for k in range(len(dictionary)):
v = dictionary[v]
print(v)
a. three
b. one
c. (‘one’, ‘two’, ‘three’)
d. two
57. Select the true statements about the try-exception block in relation to the following
example. (Select two answers.)
try:
except:
a. if you suspect that a snippet may raise an exception, you should place it in
the try block
b. The code that follows the try statement will be executed if the code in
the except clause runs into an error.
c. The code that follows the except statement will be executed if the code in
the try clause runs into an error.
d. If there is a syntax error in code located in the try block, the except branch
will not handle it, and a SyntaxError exception will be raised instead.
58. Which one if the following lines properly starts a parameterless function definition?
a. def fun:
b. def fun():
c. function fun():
d. fun function():
59. What is the output of the following snippet?
return x + 2 * y + 3 * z
a. 9
b. 0
c. 3
d. the snippet is erroneous
60. What is the output of the following code?
try:
value = input("Enter a value: ")
print(value/value)
except:
print("Bad input...")
except ZeroDivisionError:
except TypeError:
except:
print("Booo!")
a. Booo!
b. Bad input...
c. Very very bad input...
d. Very bad input...
61. What is the output of the following snippet?
def ant():
var = 1
any()
print(var)
a. 12
b. 22
c. 11
d. 21
62. The fact that tuples belong to sequence types means that:
a. they can be indexed and sliced like lists
b. they can be extended using the .append() method
c. they can be modified using the del instruction
d. they are actually lists
63. What is the output of the following snippet?
tup = (1, 2, 4, 8)
tup = tup[-2:-1]
tup = tup[-1]
print(tup)
a. 44
b. 4
c. (4)
d. (4,)
64. Assuming that my_tuple is a correctly crated tuple, the fact that tuples are immutable
means that the following instruction:
a. fun()
b. fun(0, 1, 2)
c. fun(b=0, a=0)
d. fun(b=1)
66. The following snippet:
reeturn b ** a
print(func(b=2, 2))
a. will output 4
b. will output None
c. will output 2
d. is erroneous
67. The following snippet:
def function_1(a):
return None
def function_2(a):
print(function_2(2))
a. will output 16
b. will crate a runtime error
c. will output 4
d. will output 2
68. What is the output of the following snippet?
def fun(x):
if c % 2 == 0:
return 1
else:
return 2
print(fun(fun(2)))
a. 2None
b. 1
c. the code will cause a runtime error
d. 2
69. What is the output of the following piece of code?
a. a b c
b. abc
c. asepbsepcsep
d. asepbsepc
70. Which of the following sentences are true about the code? (Select two answers)
nums = [1, 2, 3]
vals = nums
my_list = [1, 2]
for v in range(2):
my_list.insert(-1, my_list[v])
print(my_list)
a. [1, 2, 2, 2]
b. [1, 2, 1, 2]
c. [2, 1, 1, 2]
d. [1, 1, 1, 2]
72. What is the output of the following piece of code?
x = 1 // 5 + 1 / 5
print(x)
a. 0.0
b. 0
c. 0.4
d. 0.2
73. What is the output of the following piece of code?
x=1
y=2
x, y z = x, x, y
z, y, z = x, y, z
print(x, y, z)
a. 2 1 2
b. 1 2 2
c. 1 1 2
d. 1 2 1
74. What is the output of the following snippet?
print(fun(out =2))
a. 4
b. 6
c. 2
d. the snippet is erroneous and will cause SyntaxError
75. How many element does the lst list contain?
a. two
b. three
c. zero
d. one
76. What is the output of the following code if the user enters a 0 ?
try:
value = input("Enter a value: ")
print(int(value) / len(value))
except ValueError:
print("Bad input...")
except ZeroDivisionError:
except TypeErrorq:
print("Booo!")
v = dct['three']
for k in range(len(dct)):
v = dct[v]
print(v)
a. two
b. ('one', 'two', 'three')
c. three
d. one
78. What value will be assignment to the x variable?
z=0
y=0
a. False
b. 0
c. 1
d. True
79. Which of the following variable names are illegal and will cause the SystemError
exception? (Select two answers)
a. print
b. in
c. for
d. in
80. What is the expected behavior of the following program?
try:
print(5/0)
break:
except:
except(ValueError, ZeroDivisionError):
print("Too bad...")
a. The program will cause a ValueError exception and output the following message Too
bad...
b. The program will cause a SyntaxError exception
c. The program will cause a ValueError exception and output a default error message.
d. The program will raise an exception handle by the first except block.
e. The program will cause a ZeroDivisionError exception and output the following
message: Too bad...
f. The program will cause a ZeroDivisionError exception and output a default error
message.
81. Take a look at the snippet and choose the true statement:
nums = [1, 2, 3]
vals = nums
del vals[:]
a. the snippet will cause a runtime error
b. vals is longer than nums
c. nums is longer than vals
d. nums and vals have the same length
82. What is the output of the following snippet?
def fun(lst):
del lst[lst[2]]
return lst
print(fun(my_list))
a. [0 , 1, 4, 9]
b. [0, 1, 4, 16]
c. [0, 1, 9, 16]
d. [1, 4, 9, 16]
83. What is the output of the following snippet? dd
for x in dd.vals():
print(x, end="")
a. 0 1
b. 1 0
c. 0 0
d. the code is erroneous(the dict object has no vals() method)
84. What is the output of the following piece of code if the user enters two lines
containing 3 and 2 respectively?
x = int(input())
y = int(input())
x=x%y
y=y%x
print(y)
a. 1
b. 3
c. 2
d. 0
85. Which if the following snippets shows the correct way of handing multiple exceptingin a
single except clause?
a. except TypeError, ValueError, ZeroDivisinError:
# Some code.
b. except: (TypeError, ValueError, ZeroDivisinError)
# Some code.
c. except TypeError, ValueError, ZeroDivisinError
# Some code.
d. except: TypeError, ValueError, ZeroDivisinError
# Some code.
e. except: (TypeError, ValueError, ZeroDivisinError):
# Some code.
f. except (TypeError, ValueError, ZeroDivisinError)
# Some code.
86. What will be the output of the following snippet?a =
b=0
a=a^b
b=a^b
a=a^b
print (a, b)
a. 1 1
b. 0 0
c. 1 0
d. 0 1
87. How many stars (*) will the following snippet send to the console? i
=0
while i < i + 2 :
i += 1
print("*")
else:
print("*")
a. zero
b. the snippet will enter an infinite loop, printing one star per line
c. one
d. two
88. How many hashes (*) will the following snippet sent to the console? lst
for r in range(3):
for c in rang(3):
if lst[r][c] % 2 != 0:
print("#")
a. nine
b. zero
c. three
d. six
89. Knowing that a function named fun() resides in a module named mod , choosethe
correct way to import it:
a. from mod import fun
b. import fun from mod
c. from fun import mod
d. import fun
90. What is the expected output of the following code? from
random import randint
for i in range(2):
print (randint(1,2), end='')
a. 12, or 21
b. there are millions of possible combinations, and the exact output cannot be
predicted
c. 12
d. 11, 12, 21, or 22
91. During the first import of a module, Python deploys the pyc files in the
directory called:
a. mymodules
b. init
c. hashbang
d. pycache
92. What is the expected value of the result variable after the following code is
executed?
import math
print(int(result))
a. 0
b. 1
c. False
d. True
93. The following statement
118. What is true about the pip search command? (Select three answers)
a. all its searches are limited to locally installed packages
b. it needs working internet connection to work
c. it searches through all PyPI packages
d. it searches through package names only
119. When a module is imported, its contents:
a. are executed once (implicitly)
b. are ignored
c. are executed as many times as they are imported
d. may be executed (explicitly)
120. Choose the true statements. (Select two answers)
a. The version function from the platform module returns a string with your
Python version
b. The processor function from the platform module returns an integer with the
number of processes currently running in your OS
c. The version function from the platform module returns a string with your OS
version
d. The system function from the platform module returns a string with your OS
name
121. What is true about the pip install command? (Select two answers)
a. it allows the user to install a specific version of the package
b. it installs a package system-wide only when the --system option is specified
c. it installs a package per user only when the --user option is specified
d. it always installs the newest package version and it cannot be changed
122. Knowing that a function named fun() resides in a module named mod , and it
has been imported using the following line:
import mod
Choose the way it can be invoked in your code:
a. mod->fun()
b. mod::fun()
c. mod.fun()
d. fun()
123. The digraph written as #! is used to:
a. tell a Unix or Unix-like OS how to execute the contents of a Python file
b. tell an MS Windows OS how to execute the contents of a Python file
c. create a docstring
d. make a particular module entity a private one
124. A function which returns a list of all entities available in a module is called:
a. entities()
b. content()
c. dir()
d. listmodule()
125. The following code:
print(ord('c') - ord('a'))
prints:
a. 0
b. 2
c. 3
d. 1
126. The following code:
a. TopException
b. Exception
c. BaseException
d. PythonException
128. The following statement:
assert var == 0
a. is erroneous
b. will stop the program when var != 0
c. has no effect
d. will stop the program when var == 0
129. UNICODE is a standard:
a. xyzxyzxyzxyz
b. abcabcxyzxyz
c. abcabcabcxyz
d. abcxyzxyzxyz
132. UTF-8 is:
a. 0
b. 1
c. True
d. False
136. The following code:
print(chr(ord('z') - 2))
prints:
a. z
b. y
c. a
d. x
137. The following code:
x = '\' '
print(len(x))
prints:
a.
3
b.
2
c.
20
d.
1
138. Which of the following are examples of Python built-in concrete
exceptions?(Select two answers)
a. ArithemticError
b. IndexError
c. BaseException
d. ImportError
139. What will be the result of executing the following code?
class Ex(Exception):
def_init_(self,msg):
Exception._init_(self,msg + msg)
self.args = (msg,)
try:
raise Ex('ex')
except Ex as e:
print(e)
except Exception as e:
print(e)
a. it will print ex
b. it will print exex
c. it will print an empty line
d. it will raise an unhandled exception
140. A data structure described as LIFO is actually a:
a. list
b. stack
c. heap
d. tree
141. What will be the output of the following code?
class A:
A=1
print(hasattr(A, 'A'))
a. 0
b. False
c. 1
d. True
142. What will be the effect of running the following code?
class A:
def_init_(self,v):
self._a = v + 1
a = A(0)
print(a._a)
a. 2
b. The code will raise an AttributeError exception
c. 0
d. 1
143. What will be the result of executing the following code?
class A:
pass
class B(A):
pass
class C(B):
pass
print(issubclass(C,A))
a. it will print 1
b. it will print False
c. it will print True
d. it will raise an exception
144. What will be the result of executing the following code?
class A:
def_str_(self):
return 'a'
class B:
def_str_(self):
return 'b'
pass
o = C()
print(o)
a. it will print b
b. it will print c
c. it will print a
d. it will raise an exception
145. What will be the result of executing the following code?
class A:
def a(self):
print('a')
class B:
def a(self):
self.a()
o = C()
o.c()
try:
raise Exception(1,2,3)
except Exception as e:
print (len(e.args))
a. it will print 1
b. it will print 2
c. it will raise as unhandled exception
d. it will print 3
147. What will be the output of the following code?
class A:
X=0
self.Y = v
A.X += v
a = A()
b = A(1)
c = A(2)
print(c.X)
a.2
b.3
c.0
d.1
148. If the class’s constructor is declared as below, which one of the assignments
is valid?
class Class:
pass
a. object = Class
b. object = Class()
c. object = Class(self)
d. object = Class(object)
149. What will be the result of executing the following code?
def f(x):
try:
x=x/x
except:
print("a",end='')
else:
print("b",end='')
finally:
print("c",end='')
f(1)
f(0)
a.
it will raise an unhandled exception
b.
it will print bcac
c.
it will print acac
d.
it will print bcbc
150. If there is a superclass named A and a subclass named B, which one of the
presented invocations should you put instead of the comment?
class A:
self.a = 1
class B(A):
self.b = 2
a. A. init (self)
b. init ()
c. A. init ()
d. A. init (1)
151. What will be the result of executing the following code?
class A:
pass
a = A(1)
print(hasattr(a,'A'))
a. 1
b. False
c. it will raise an exception
d. True
152. What will be the result of executing the following code?
class A:
return 'a'
class B(A):
return 'b'
class c(B):
pass
o = C()
print(o)
a. it will print c
b. it will print b
c. it will print a
d. it will raise an exception
153. What will be the output of the following code?
class A:
self.v =v
def set(self,v):
self.v = v
return v
a = A()
print(a.set(a.v + 1))
a. 2
b. 1
c. 3
d. 0
154. What will be the result of executing the following code?
class A:
v=2
class B(A):
v=1
class C(B):
pass
o =C()
print(o.v)
def I():
s = 'abcdef'
for c in s[::2]:
yield c
for x in I():
a. afun
b. lambda
c. def
d. yield
157. Select the true statements. (Select two answers)
a. The lambda function can accept a maximum of two arguments
b. The lambda function can evaluate multiple expressions
c. The lambda function can evaluate only one expressrion
d. The lambda function can accept any number of arguments
158. Look at the code below:
my_list = [1, 2, 3]
print(foo)
Which snippet would you insert in order for the program to output the following result
(tuple):
1, 4, 27
a. foo = list(map(lambda x: x**x, my_list))
b. foo = tuple(map(lambda x: x*x, my_list))
c. foo = list(map(lambda x: x*x, my_list))
d. foo = tuple(map(lambda x: x**x, my_list))
159. What is the expected output of the following code?
date_2 = date(1992, 2, 5)
print(date_1 - date_2)
a. 345
b. 345 days
c. 345, 0:00:00
d. 345 days, 0:00:00
160. Which program will produce the following output:
Mo Tu We Th Fr Sa Su
a. import calendar
b. print(calendar.weekheader(3))
c. import calendar
d. print(calendar.weekheader(2))
e. import calendar
f. print(calendar.week)
g. import calendar
h. print(calendar.weekheader())
def o(p):
def q():
return'*' *p
return q
r = o(1)
s = o(2)
print(r9) + s())
my_tuple = (0, 1, 2. 3, 4, 5, 6)
print(foo)
Which snippet would you insert in order for he program to output the following result
(list):
[2, 3, 4, 5, 6]
def fun(n):
s = '+'
for i in range(n):
s += s
yield s
for x in fun(2):
print(x, end='')
a. It will print+++
b. It will print ++
c. It will print ++++++
d. It will print +
164. What is the meaning of the value represented by errno.EEXITS ?
a. File doesn’t exist
b. Bad file number
c. Permission denied
d. File exists
165. What is the expected result of the following code?
b = bytearray(3)
print(b)
a. 3
b. bytearray(b'\x00\x00\x00')
c. bytearray(0, 0, 0)
d. bytearray(b'3')
166. What is the expected output of the following code?
perint(datetime.strftime('%y/%B/%d %H:%M:%s'))
a. 19/November/27 11:27:22
b. 2019/Nov/27 11:27:22
c. 2019/11/27 11:27:22
d. 19/11/27 11:27:22
167. What is the expected output of the following code?
import os
os.mkdir('pictures')
os.chdir('pictures')
os.mkdir('thumbnails')
os.chdir('thumbnails')
os.mkdir('tmp')
os.chdir('../')
print(os.getcwd())
import os
os.mkdir('thumbnails')
os.chdir('thumbnails')
os.mkdir(size)
print(os.listdir())
import calendar
c = calendar.Calendar()
print(weekday, end="")
a. 1234567
b. Su Mo Tu We Th Fr Sa
c. 01234567
d. Mo Tu We Th Fr Sa Su
170. The following code:
x = "\\\\"
print(len(x))
a.will print 1
b.will print 2
c.will cause an error
d.will print 3
171. What information can be read using the uname function provided by
the os module? (Select two answers)
import os
os.mkdir('pictures')
os.chdir('pictures')
print(os.getcwd())
assert var != 0
a. ia erroneous
b. has no effect
c. will stop the program when var == 0
d. will stop the program whrn var !=0
173. What is he except output of the following code?
class A:
A=1
self.a = 0
print(hasattr(A, 'a'))
a. 0
b. True
c. 1
d. False
174. What is the excepted result of the following code?
print(delta * 2)
a. 28 days, 22:00:00
b. 2 weeks, 14 days, 22 hours
c. 7 days, 22:00:00
d. The code will raise an exception
175. What is the excepted output of the following code?
class A:
self.v +=v
return self.v
a = A()
b=a
b.set()
print(a.v)
a. 1
b. 0
c. 2
d. 3
176. What is the expected effect of running the following code?
class A:
def init (self, v):
self. a = v + 1
a = A(0)
print(a. a)
a. mod:fun()
b. mod::fun()
c. fun()
d. mod.fun()
178. What output will appear after running the following snippet?
import random
print(a, b,
Which lines of code would you insert so that it is possible for the program to output the
following result:
6 82 0
a. a = random.randint(0, 100)
b. b = random.randrange(10, 100, 3)
c. c = random.choice((0, 100, 3))
e. b = random.randrange(10, 100, 3)
f. c = random.randint(0, 100)
g. a = random.randrange(10, 100, 3)
h. b = random.randint(0, 100)
j. a = random.randint(0, 100)
l. c = random.randrange(10, 100, 3)
print(datetime_1 - datetime_2)
a. o days
b. 0 days, 11:27:22
c. 11:27:22
d. 11 hours, 27 minutes, 22 seconds
181. What is the expected result of the following code?
import calendar
calendar.setfirstweekday(calendar.SUNDAY)
print(calendar.weekheader(3))
a. Su Mo Tu We Th We Fr Sa
b. Sun Mon Tue Wed Thu Fri Sat
c. Tu
d. Tue
182. what is the expected result of executing the following code?
class A:
print(list(foo))
Which line would you insert in order for the program to produce the expected output?
class I:
self.s = 'abc'
self.i = 0
return self
raise StopIteration
v = self.s[self.i]
self.i +=1
return v
for x in I():
print(x, end='')
a.
The code will print 210
b.
The code will print abc
c.
The code will print 012
d.
The code will print cba
185. The complied Python bytecode is stored in files which have their names
ending with:
a. py
b. pyb
c. pc
d. pyc
186. Which pip command would you use to uninstall a previously install package?
a. pip delete packagename
b. pip –uninstall packagename
c. pip –remove packagename
d. pip uninstall packagename
187. What is the excepted result of executed the following code?
try:
raise Exception(1, 2, 3)
except Exception as e:
print(len(e.args))
try:
raise Exception
except BaseException:
print("a")
except Exception:
print("b")
except:
print("c")
a. b
b. a
c. An error message
d. 1
189. What is the expected result of executing the following code?
class A:
pass
class B(A):
pass
class C(B):
pass
print(issubclass(A, C))
print(float("1.3"))
print(chr(ord('p) + 2))
will print:
a. q
b. s
c. r
d. t
193. If there are more than one except: branch after the try: clause, we can say that:
a. exactly one except: block will be executed
b. one or more except: blocks will be executed
c. not more than one except: block will be executed
d. none of the except: blocks will be executed
194. If the class constructor is declared in the following way:
class Class:
pass
try:
raise Exception
except:
print("c")
except BaseException:
print("a")
except Exception:
print("b")
def my_fun(n):
s = '+'
for i in range(n):
s += s
yield s
for x in my_fun(2):
print(x, end='')
print(foo)
Which line would you insert in order for the program to produce the expected output?
[1, 9]
def o(p):
def q():
return '*' * p
return q
r = o(1)
s = o(2)
print(r() + s())
print( name )
a. main
b. p.py
c. main
d. p.py
202. Assuming that the open() invocation has gone successfully, the following
snippet:
print(x)
will:
q = s.read(1)
will read:
import os
os.mkdir('pictures')
os.chdir('pictures')
print(os.getcwd())
# file a.py
print("a", end='')
# file b.py
import a
print("b", end='')
# file c.py
print("c", end='')
import a
import b
a. cab
b. cab
c. abc
d. bac
207. What is the expected result of executing the followinf code?
class A:
pass
a = A(1)
print(hasattr(a, 'A'))
x = " \\"
print(len(x))
a.will print 1
b.will print 3
c.will print 2
d.will cause an error
209. Which of the following commands would you use to check pip ‘s version?
(Select two answers)
a. pip version
b. pip --version
c. pip–version
d. pip3 --version
210. What is the expected output of the following snippet?
a = True
b = False
a = a or b
b = a and b
a = a or b
print(a, b)
a. False False
b. True False
c. False True
d. True False
211. What is the expected output of the following snippet?
i=4
while i > 0 :
i -= 2
print("*")
if i == 2:
break
else:
print("*")
a. two
b. one
c. zero
d. The snippet will enter an infinite loop, constantly printing one * per line
213. What is the sys.stdout stream normally associated with?
a. The printer
b. The keyboard
c. A null device
d. The screen
214. What is the excepted output of the following snippet?
class X:
pass
class Y(X):
pass
class Z(Y):
pass
x = X()
z = Z()
a. True True
b. True False
c. False True
d. False False
215. What is the excepted output of the following snippet?
class A:
self.name = name
a = A("class")
print(a)
a. class
b. name
c. A number
d. A string ending with a long hexadecimal number
216. What is the excepted result of executing the following code?
class A:
pass
class B:
pass
pass
print(issubclass(C, A) and issubclass(C, B))
print(datetime.strftime('%Y/%m/%d %H:%M:%S'))
a. 19/11/27 11:27:22
b. 2019/Nov/27 11:27:22
c. 2019/11/27 11:27:22
d. 2019/November/27 11:27:22
218. What is the excepted output of the following code?
my_string_1 = 'Bond'
print(my_string_1.isalpha(), my_string_2.isalpha())
a. False True
b. True True
c. False False
d. True False
219. The meaning of a Keyword argument is determined by its:
a. both name and value assigned to it
b. position within the argument list
c. connection with existing variables
d. value only
220. Knowing that the function named m, and the code contains the
following import statement:
from f import m
Choose the right way to invoke the function:
a. mod.f()
b. The function cannot be invoked because the import statement is invalid
c. f()
d. mod:f()
221. The Exception class contains a property named args -what is it?
a. A dictionary
b. A list
c. A string
d. A tuple
222. Which is the expected behavior of the following snippet?
def fun(x):
return 1 if x % 2 != else 2
print(fun(fun(1)))
for k in sorted(d.values()):
a. 123
b. 312
c. 321
d. 231
225. Select the true statements.(Select two answers)
a. The first parameter of a class method dose not have to be named self
b. The first parameter of a class method must be named self
c. If a class contains the init method, it can return a value
d. If a class contains the init method, it cannot return any value
226. Select the true statements. (Select two answers)
a. PyPI is short for Python Package Index
b. PyPI is the only existing Python repository
c. PyPI is one of many existing Python repository
d. PyPI is short for Python Package Installer
227. What is the expected output of the following snippet?
t = (1, 2, 3, 4)
t = t[-2:-1]
t = t[-1]
print(t)
a.
(3)
b.
(3,)
3b.
c.
33
228. Which of the following functions provide by the os module are available in
both Windows and Unix? (Select two answers)
a. chdir()
b. getgid()
c. getgroups()
d. mkdir()
229. What is the expected output of the following piece of code?
v = 1 + 1 // 2 + 1 / 2 + 2
a. 4.0
b. 3
c. 3.5
d. 4
230. If s is a stream opened in read mode, the following line:
q = s.readlines()
will assign q as :
a. dictionary
b. tuple
c. list
d. string
231. Which of the following sentences is true about the snippet below?
str_1 = 'string'
str_2 = str_1[:]
class A:
pass
def f(self):
return 1
def g():
return self.f()
a = A()
print(a.g())
print( name )
a. main
b. modle.py
c. main
d. module.py
234. What is the excepted output of the following code?
def a(x):
def b():
return x + x
return b
x = a('x)
y = a('')
print(x() + y())
a. xx
b. xxxx
c. xxxxxx
d. x
235. What is the excepted behavior of the following piece of code?
x = 16
while x > 0:
print('*', end='')
x //= 2
a.
The code will output *****
b.
The code will output ***
c.
The code will output *
d.
The code will error an infinite loop
236. A package directory/folder may contain a file intended to initialize the
package. What is its name?
a. init.py
b. init.py
c. init .
d. init .py
237. If there is a finally: branch inside the try: block, we can say that:
a. the finally: branch will always be executed
b. the finally: branch won’t be executed if any of the except: branch is executed
c. the finally: branch won’t be executed if no exception is raised
d. the finally: branch will be executed when there is no else: branch
238. What value will be assigned to the x variable?
z=2
y=1
a. True
b. False
c. 0
d. 1
239. If you want to write a byte array’s content to a stream, which method can you
use?
a. writeto()
b. writefrom()
c. write()
d. writebytearray()
240. What is the expected behavior of the following snippet?
try:
raise Exception
except:
print("c")
except BaseException:
print("a")
except Exception:
print("b")
print(fun(par2 = 1, 2))
x, y, z = 3, 2, 1
z, y, x = x, y, z
print(x, y, z)
a. 213
b. 122
c. 321
d. 123
243. What is the expected output of the following snippet?
d = {}
d['2'] = [1, 2]
d['1'] = [3, 4]
for x in d.keys():
print(d[x][1], end="")
a. 24
b. 31
c. 13
d. 42
244. What is the expected output of the following snippet?
try:
raise Exception
except BaseException:
print("a", end='')
else:
print("b", end='')
finnaly:
print("c")
a. bc
b. a
c. ab
d. ac
245. If the class constructor is declare as below:
class Class:
pass
y = input()
x = input()
print(x + y)
a. 2
b. 21
c. 12
d. 3
247. What is the expected behavior of the following snippet?
my_string = 'abcdef'
def fun(s):
del s[2]
return s
print(fun(my_string))
d[k] = v
my_dictionary = {}
class A:
A=1
self.a = 0
print(hasattr(A, 'A'))
a. False
b. 1
c. 0
d. True
250. What is the expected behavior of the following code?
x = """
"""
print(len(x))
import calendar
c = calendar.Calendar(calendar.SUNDAY)
a. 7123456
b. 6012345
c. Su Mo Tu We Th Fr Sa
d. Su
252. What is the expected output of the following code?
def fun(n):
s=''
for i in range(n):
s += '*'
yield s
for x in fun(3):
print(x, end='')
a. ****
b. ******
c. 2***
d. *
253. What is the expected output of the following code?
t = (1, )
t = t[0] + t[0]
print(t)
a. 2
b. (1, )
c. (1, 1)
d. 1
254. What is the expected result of executing the following code?
class A:
def a(self):
print('a')
class B:
def a(self):
print('b')
def c(self):
self.a()
o = C()
o.c()
my_list = [1, 2, 3, 4]
d = {1: 0, 2: 1, 3: 2, 0: 1}
x=0
for y in range(len(d)):
x = d[x]
print(x)
a.
The code will output 0
b.
The code will output 1
c.
The code will cause a runtime error
d.
The code will output 2
257. What pip operation would you use to check what Python package have been
installed so far?
a. show
b. list
c. help
d. dir
258. What is true about the following line of code?
print(len((1, )))
# function body
a. fun(b=0, b=0)
b. fun(a=1, b=0, c=0)
c. fun(1, c=2)
d. fun(0)
260. What is the expected behavior of the following code?
import os
os.makedirs('pictures/thumbnails')
os.rmdir('pictures')
a. The code will delete both the pictures and thumbnails directories
b. The code will delete the pictures directory only
c. The code will raise an error
d. the code will delete the thumbnails directory only
261. What is true about the following piece of code?
x = "\"
print(len(x))
class A:
A=1
self.v = v +A.A
A.A += 1
A.A += 1
return
a = A()
a.set(2)
print(a.v)
a. 7
b. 1
c. 3
d. 5
264. How many empty lines will the following snippet send to the console?
if len(element) < 2:
print()
a. two
b. three
c. zero
d. one
265. The following fragment of code is written using a for loop. Re-write it using a
while
for i in range(1, 16) :
if i % 3 == 0 :
print (i)
Ans: i = 1
while i < 16:
if i % 3 == 0 :
print (i)
i += 1