Earn Rs.2500/-Per Day: PE1 & PE2: Python Essentials - Final Test
Earn Rs.2500/-Per Day: PE1 & PE2: Python Essentials - Final Test
com/about-us/)
ExamPoster (https://examposter.com/)
Earn Rs.2500/- Per Day Open
MonsterIndia Sign Up
PE : All Parts
What will happen when you attempt to compile
and run the following code?
(https://examposter.com/what-will-happen-
Python Essentials
when-you-attempt-to-compile-and-run-the-
PE1 : Python Essentials 1 PE2 : Python Essentials 2 following-code-167/)
(https://examposter.com/python-institute/pe1-python- (https://examposter.com/python-institute/pe2-python-
What will happen when you attempt to compile
essentials-1-basics/) essentials-2-intermediate/) and run the following code?
a = True
b = False
a = a or b
b = a and b
Meta
a = a or b
Log in (https://examposter.com/wp-login.php)
print(a, b) Entries feed (https://examposter.com/feed/)
Comments feed
(https://examposter.com/comments/feed/)
3
1
2
0
3. How many stars * will the following snippet send to the console?
i = 4
while i > 0 :
i -= 2
print("*")
if i == 2:
break
else:
print("*")
two
one
zero
The snippet will enter an infinite loop, constantly printing one * per line
4. What is the sys.stdout stream normally associated with?
The printer
The keyboard
A null device
The screen
5. What is the excepted output of the following snippet?
class X:
pass
class Y(X):
pass
class Z(Y):
pass
x = X()
z = Z()
True True
True False
False True
False False
6. What is the excepted output of the following snippet?
class A:
def __init__(self,name):
self.name = name
a = A("class")
print(a)
class
name
A number
A string ending with a long hexadecimal number
7. What is the excepted result of executing the following code?
class A:
pass
class B:
pass
pass
print(datetime.strftime('%Y/%m/%d %H:%M:%S'))
19/11/27 11:27:22
2019/Nov/27 11:27:22
2019/11/27 11:27:22
2019/November/27 11:27:22
9. What is the excepted output of the following code?
my_string_1 = 'Bond'
print(my_string_1.isalpha(), my_string_2.isalpha())
False True
True True
False False
True False
10. The meaning of a Keyword argument is determined by its:
from f import m
mod.f()
The function cannot be invoked because the import statement is invalid
f()
mod:f()
12. The Exception class contains a property named args -what is it?
A dictionary
A list
A string
A tuple
13. What is PEP 8?
A document that provides coding conventions and style guide for the C code computing the C implementation of
Python
A document that describes the development and release schedule for Python versions
A document that describes an extension to Python’s import mechanism which improves sharing of Python
source code files
A document that provides coding conventions and style guide for Python code
14. Which is the expected behavior of the following snippet?
def fun(x):
return 1 if x % 2 != else 2
print(fun(fun(1)))
The program will output None
The code will cause a runtime error
The program will output 2
===
is
==
=
16. What is the name of the directory/folder created by Python used to store pyc files?
__pycfiles
__pyc__
__pycache__
__cache__
17. What can you do if you want tell your module users that a particular variable should not be
accessed directly?
for k in sorted(d.values()):
t = (1, 2, 3, 4)
t = t[-2:-1]
t = t[-1]
print(t)
(3)
(3,)
3
33
22. What is the expected effect of running the following code?
class A:
self._a = v + 1
a = A(0)
print(a._a)
chdir()
getgid()
getgroups()
mkdir()
24. What is the expected output of the following piece of code?
v = 1 + 1 // 2 + 1 / 2 + 2
4.0
3
3.5
4
25. If s is a stream opened in read mode, the following line:
q = s.readlines()
will assign q as :
dictionary
tuple
list
string
26. Which of the following sentences is true about the snippet below?
str_1 = 'string'
str_2 = str_1[:]
def __init__(self):
pass
def f(self):
return 1
def g():
return self.f()
a = A()
print(a.g())
print(__name__)
main
modle.py
__main__
__module.py__
29. 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())
xx
xxxx
xxxxxx
x
30. What is the excepted behavior of the following piece of code?
x = 16
while x > 0:
print('*', end='')
x //= 2
the finally: branch won’t be executed if any of the except: branch is executed
the finally: branch will be executed when there is no else: branch
33. What value will be assigned to the x variable?
z = 2
y = 1
True
False
0
1
34. If you want to write a byte array’s content to a stream, which method can you use?
writeto()
writefrom()
write()
writebytearray()
35. 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))
z, y, x = x, y, z
print(x, y, z)
2 1 3
1 2 2
3 2 1
1 2 3
38. 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="")
24
31
13
42
39. What is the expected output of the following snippet?
try:
raise Exception
except BaseException:
print("a", end='')
else:
print("b", end='')
finnaly:
print("c")
bc
a
ab
ac
40. If the class constructor is declare as below:
class Class:
def __init__(self):
pass
object = Class()
object = Class(1,2)
object = Class(None)
object = Class(1)
41. What is the expected output of the following code?
from datetime import timedelta
print(delta)
7 days, 11:00:00
2 weeks, 11:00:00
1 week, 7 days, 11 hours
14 days, 11:00:00
42. What is the expected output of the following piece of code if the user enters two lines
containing 1 and 2 respectively?
y = input()
x = input()
print(x + y)
2
21
12
3
43. 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 = {}
A = 1
def __init__(self):
self.a = 0
print(hasattr(A, 'A'))
False
1
0
True
46. What is the expected behavior of the following code?
x = """
"""
print(len(x))
c = calendar.Calendar(calendar.SUNDAY)
7 1 2 3 4 5 6
6 0 1 2 3 4 5
Su Mo Tu We Th Fr Sa
Su
48. 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='')
****
******
2***
*
49. What is the expected output of the following code?
t = (1, )
t = t[0] + t[0]
print(t)
2
(1, )
(1, 1)
1
50. 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]
print(my_list)
d = {1: 0, 2: 1, 3: 2, 0: 1}
x = 0
for y in range(len(d)):
x = d[x]
print(x)
show
list
help
dir
54. What is true about the following line of code?
print(len((1, )))
# function body
fun(b=0, b=0)
fun(a=1, b=0, c=0)
fun(1, c=2)
fun(0)
56. What is the expected behavior of the following code?
import os
os.makedirs('pictures/thumbnails')
os.rmdir('pictures')
The code will delete both the pictures and thumbnails directories
x = "\"
print(len(x))
class A:
A = 1
self.v = v +A.A
A.A += 1
self.v +=v
A.A += 1
return
a = A()
a.set(2)
print(a.v)
7
1
3
5
60. How many empty lines will the following snippet send to the console?
my_list = [[c for c in range(r)] for r in range(3)]
if len(element) < 2:
print()
two
three
zero
one
PE : All Parts
Python Essentials
PE1 : Python Essentials 1 PE2 : Python Essentials 2
(https://examposter.com/python-institute/pe1-python- (https://examposter.com/python-institute/pe2-python-
essentials-1-basics/) essentials-2-intermediate/)