1. What is the expected output of the following snippet?
2. a = True
3. b = False
4. a = a or b
5. b = a and b
6. a = a or b
print(a, b)
o False False
o True False
o False True
o True False
7. What is the expected output of the following snippet?
print(len([i for i in range(0, -2)]))
o 3
o 1
o 2
o 0
8. How many stars * will the following snippet send to the console?
9. i = 4
10. while i > 0 :
11. i -= 2
12. print("*")
13. if i == 2:
14. break
15. else:
print("*")
o two
o one
o zero
o The snippet will enter an infinite loop, constantly printing one * per line
16.What is the sys.stdout stream normally associated with?
o The printer
o The keyboard
o A null device
o The screen
17.What is the excepted output of the following snippet?
18. class X:
19. pass
20. class Y(X):
21. pass
22. class Z(Y):
23. pass
24. x = X()
25. z = Z()
print(isinstance(x, z), isinstance(z, X))
o True True
o True False
o False True
o False False
26.What is the excepted output of the following snippet?
27. class A:
28. def __init__(self,name):
29. self.name = name
30. a = A("class")
print(a)
o class
o name
o A number
o A string ending with a long hexadecimal number
31.What is the excepted result of executing the following code?
32. class A:
33. pass
34. class B:
35. pass
36. class C(A, B):
37. pass
print(issubclass(C, A) and issubclass(C, B))
o The code will print True
o The code will raise an exception
o The code will print an empty line
o The code will print False
38.What is the excepted output of the following code?
39. from datetime import datetime
40.
41. datetime = datatime(2019, 11, 27, 11, 27, 22)]
print(datetime.strftime('%Y/%m/%d %H:%M:%S'))
o 19/11/27 11:27:22
o 2019/Nov/27 11:27:22
o 2019/11/27 11:27:22
o 2019/November/27 11:27:22
42.What is the excepted output of the following code?
43. my_string_1 = 'Bond'
44. my_string_2 = 'James Bond'
45.
print(my_string_1.isalpha(), my_string_2.isalpha())
o False True
o True True
o False False
o True False
46.The meaning of a Keyword argument is determined by its:
o both name and value assigned to it
o position within the argument list
o connection with existing variables
o value only
47.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:
o mod.f()
o The function cannot be invoked because the import statement is invalid
o f()
o mod:f()
48.The Exception class contains a property named args -what is it?
o A dictionary
o A list
o A string
o A tuple
49.What is PEP 8?
o A document that provides coding conventions and style guide for the C code
computing the C implementation of Python
o A document that describes the development and release schedule for Python
versions
o A document that describes an extension to Python’s import mechanism which
improves sharing of Python source code files
o A document that provides coding conventions and style guide for Python code
50.Which is the expected behavior of the following snippet?
51. def fun(x):
52. return 1 if x % 2 != else 2
print(fun(fun(1)))
o The program will output None
o The code will cause a runtime error
o The program will output 2
o The program will output 1
53.Which operator would you use to check whether two values are
equal?
o ===
o is
o ==
o =
54.What is the name of the directory/folder created by Python used to
store pyc files?
o __pycfiles
o __pyc__
o __pycache__
o __cache__
55.What can you do if you want tell your module users that a
particular variable should not be accessed directly?
o Start its name with __or__
o Start its name with a capital letter
o Use its number instead of its name
o Build its name with lowercase letters only
56.What is the expected output of the following snippet?
57. d = ('one': 1, 'three': 3, 'two':2)
58. for k in sorted(d.values()):
print(k, end=' ')
o 123
o 3 1 2
o 3 2 1
o 2 3 1
59.Select the true statements.(Select two answers)
o The first parameter of a class method dose not have to be named self
o The first parameter of a class method must be named self
o If a class contains the __init__ method, it can return a value
o If a class contains the __init__ method, it cannot return any value
60.Select the true statements. (Select two answers)
o PyPI is short for Python Package Index
o PyPI is the only existing Python repository
o PyPI is one of many existing Python repository
o PyPI is short for Python Package Installer
61.What is the expected output of the following snippet?
62. t = (1, 2, 3, 4)
63. t = t[-2:-1]
64. t = t[-1]
print(t)
o (3)
o (3,)
o 3
o 33
65.What is the expected effect of running the following code?
66. class A:
67. def __init__(self, v):
68. self._a = v + 1
69. a = A(0)
print(a._a)
o The code will raise an AttributeError exception
o The code will output 1
o The code will output 2
o The code will output 0
70.Which of the following functions provide by the os module are
available in both Windows and Unix? (Select two answers)
o chdir()
o getgid()
o getgroups()
o mkdir()
71.What is the expected output of the following piece of code?
v = 1 + 1 // 2 + 1 / 2 + 2
o 4.0
o 3
o 3.5
o 4
72.If s is a stream opened in read mode, the following line:
q = s.readlines()
will assign q as :
o dictionary
o tuple
o list
o string
73.Which of the following sentences is true about the snippet below?
74. str_1 = 'string'
str_2 = str_1[:]
o str_1 is longer than str_2
o str_1 and str_2 are different (but equal) strings
o str_1 and str_2 are different names of the same string
o str_2 is longer than str_1
75.What is the expected result of executed the following code?
76. class A:
77. def __init__(self):
78. pass
79. def f(self):
80. return 1
81. def g():
82. return self.f()
83. a = A()
print(a.g())
o The code will output True
o The code will output 0
o The code will output 1
o The code will raise an exception
84.What is the expected output of the following code, located in the
file module.py ?
print(__name__)
o main
o modle.py
o __main__
o __module.py__
85.What is the excepted output of the following code?
86. def a(x):
87. def b():
88. return x + x
89. return b
90. x = a('x)
91. y = a('')
print(x() + y())
o xx
o xxxx
o xxxxxx
o x
92.What is the excepted behavior of the following piece of code?
93. x = 16
94. while x > 0:
95. print('*', end='')
x //= 2
o The code will output *****
o The code will output ***
o The code will output *
o The code will error an infinite loop
96.A package directory/folder may contain a file intended to initialize
the package. What is its name?
o init.py
o __init.py__
o __init__.
o __init__.py
97.If there is a finally: branch inside the try: block, we can say
that:
o the finally: branch will always be executed
o the finally: branch won’t be executed if any of the except: branch is
executed
o the finally: branch won’t be executed if no exception is raised
o the finally: branch will be executed when there is no else: branch
98.What value will be assigned to the x variable?
99. z = 2
100. y = 1
x = y < z or z > y and y > z or z < y
o True
o False
o 0
o 1
101. If you want to write a byte array’s content to a stream, which
method can you use?
o writeto()
o writefrom()
o write()
o writebytearray()
102. What is the expected behavior of the following snippet?
103. try:
104. raise Exception
105. except:
106. print("c")
107. except BaseException:
108. print("a")
109. except Exception:
print("b")
o The code will cause an error
o The code will output b
o The code will output c
o The code will output a
110. What is true about the following code snippet?
111. def fun(par2, par1):
112. return par2 + par1
print(fun(par2 = 1, 2))
o The code is erroneous
o The code will output 3
o The code will output 2
o The code will output 1
113. What is the expected output of the following piece of code?
114. x, y, z = 3, 2, 1
115. z, y, x = x, y, z
print(x, y, z)
o 2 1 3
o 1 2 2
o 3 2 1
o 123
116. What is the expected output of the following snippet?
117. d = {}
118. d['2'] = [1, 2]
119. d['1'] = [3, 4]
120. for x in d.keys():
print(d[x][1], end="")
o 24
o 31
o 13
o 42
121. What is the expected output of the following snippet?
122. try:
123. raise Exception
124. except BaseException:
125. print("a", end='')
126. else:
127. print("b", end='')
128. finnaly:
print("c")
o bc
o a
o ab
o ac
129. If the class constructor is declare as below:
130. class Class:
131. def __init__(self):
pass
which one of the assignment is valid?
o object = Class()
o object = Class(1,2)
o object = Class(None)
o object = Class(1)
132. What is the expected output of the following code?
133. from datetime import timedelta
134. delta = timedelta(weeks = 1, days = 7, hours =
11)
print(delta)
o 7 days, 11:00:00
o 2 weeks, 11:00:00
o 1 week, 7 days, 11 hours
o 14 days, 11:00:00
135. What is the expected output of the following piece of code if the
user enters two lines containing 1 and 2 respectively?
136. y = input()
137. x = input()
print(x + y)
o 2
o 21
o 12
o 3
138. What is the expected behavior of the following snippet?
139. my_string = 'abcdef'
140. def fun(s):
141. del s[2]
142. return s
print(fun(my_string))
o The program will cause an error
o The program will output abdef
o The program will output acdef
o The program will output abcef
143. What is true about the following snippet?
144. def fun(d, k, v):
145. d[k] = v
146. my_dictionary = {}
print(fun(my_dictionary, '1', 'v'))
o The code is erroneous
o The code will output None
o The code will output v
o The code will output 1
147. What is the expected output of the following code?
148. class A:
149. A = 1
150. def __init__(self):
151. self.a = 0
print(hasattr(A, 'A'))
o False
o 1
o 0
o True
152. What is the expected behavior of the following code?
153. x = """
154. """
print(len(x))
o The code will output 2
o The code will output 3
o The code will cause an error
o The code will output 1
155. What is the expected output of the following code?
156. import calendar
157. c = calendar.Calendar(calendar.SUNDAY)
158. for weekday in c.iterweekdays():
print(weekday, end=" ")
o 7 1 2 3 4 5 6
o 6012345
o Su Mo Tu We Th Fr Sa
o Su
159. What is the expected output of the following code?
160. def fun(n):
161. s = ' '
162. for i in range(n):
163. s += '*'
164. yield s
165. for x in fun(3):
print(x, end='')
o ****
o ******
o 2***
o *
166. What is the expected output of the following code?
167. t = (1, )
168. t = t[0] + t[0]
print(t)
o 2
o (1, )
o (1, 1)
o 1
169. What is the expected result of executing the following code?
170. class A:
171. def a(self):
172. print('a')
173. class B:
174. def a(self):
175. print('b')
176. class C(A, B):
177. def c(self):
178. self.a()
179. o = C()
o.c()
o The code will print c
o The code will print a
o The code will raise an exception
o The code will print b
180. What is the expected behavior of the following code snippet?
181. my_list = [1, 2, 3, 4]
182. my_list = list(map(lambda x: 2*x, my_list))
print(my_list)
o The code will cause a runtime error
o The code will output 1 2 3 4
o the code will output 10
o The code will output 2 4 6 8
183. What is the expected behavior of the following piece of code?
184. d = {1: 0, 2: 1, 3: 2, 0: 1}
185. x = 0
186. for y in range(len(d)):
187. x = d[x]
print(x)
o The code will output 0
o The code will output 1
o The code will cause a runtime error
o The code will output 2
188. What pip operation would you use to check what Python
package have been installed so far?
o show
o list
o help
o dir
189. What is true about the following line of code?
print(len((1, )))
o The code will output 0
o The code is erroneous
o The code will output 1
o The code will output 2
190. Which line properly invokes the function defined as below?
191. def fun(a, b, c=0):
# function body
o fun(b=0, b=0)
o fun(a=1, b=0, c=0)
o fun(1, c=2)
o fun(0)
192. What is the expected behavior of the following code?
193. import os
194. os.makedirs('pictures/thumbnails')
os.rmdir('pictures')
o The code will delete both the pictures and thumbnails directories
o The code will delete the pictures directory only
o The code will raise an error
o the code will delete the thumbnails directory only
195. What is true about the following piece of code?
print("a", "b", "c", sep=" ' ")
o The code is erroneous
o The code will output abc
o The code will output a'b'c
o The code will output a b c
196. What is the expected behavior of the following code?
197. x = "\"
print(len(x))
o The code will output 3
o The code will cause an error
o The code will output a2
o The code will output 1
198. What is the expected output of the following code?
199. class A:
200. A = 1
201. def __init__(self, v=2):
202. self.v = v +A.A
203. A.A += 1
204. def set(self, v):
205. self.v +=v
206. A.A += 1
207. return
208. a = A()
209. a.set(2)
print(a.v)
o 7
o 1
o 3
o 5
210. How many empty lines will the following snippet send to the
console?
211. my_list = [[c for c in range(r)] for r in
range(3)]
212. for element in my_list:
213. if len(element) < 2:
print()
o two
o three
o zero
o one