Python 3.4 Fiverr Skills Test
What will be the correct output of the following Python code?
class St:
stm = 'B'
stm = 'A'
def __init__(self, r):
self.r = r
a = St(101)
b = St(102)
print(a.stm)
print(b.stm)
print(a.r)
print(St.stm)
A
A
102
A
B
B
102
B
B
B
101
B
A
A
101
A
Analyse the given Python code and choose the correct output from the given options.
pdata = 50
try:
pdata = pdata/0
except ZeroDivisionError:
print('0 ', end = '')
else:
print('1', end = '')
try:
pdata = pdata/5
except:
print('1', end = '')
else:
print('0', end = '')
0 1
0 0
1 0
1 1
The items() method in Python is used for returning the list with all dictionary keys and values.
True
False
This question is based on the graphic shown below.
Choose the correct output of the given Python code.
5 2
8 2
5 3
8 3
Analyse the given Python code and answer the question that follows.
import math
a = math.pi/6
b = 3
c = 4
print (math.tan(a))
print ("result = ", end="")
print (math.hypot(b,c))
What will be the correct output of the above Python code?
0.4773502691896257
result = 4.0
0.5773502691896257
result = 5.0
0.6773502691896257
result = 6.0
0.7773502691896257
result = 7.0
Which of the following port numbers is used for the Telnet protocol in Python?
20
23
25
70
Find the output of the following Python code and choose the correct answer from the given options.
n1 = 1.5
n2 = 6.3
s = float(n1) + float(n2)
print('{0}'.format(s))
s //= 3
print(s)
7.8
23
4 7.8
10.8
7.8
9.0
7.8
2.0
In relation to the exceptions in Python, which of the given exceptions is raised when a generated error code does not fall into any category?
NotImplementedError
TypeError
RuntimeError
SystemError
This question is based on the graphic shown below.
The Python code given in Figure 1 of the image was supposed to give the output that is given in Figure 2, but lines number 14 and 24 are coded incorrectly. Choose the correct lines from the following options that will replace both the lines to obtain the desired output.
Line 14: a -= 1
Line 24: while e>=1:
Line 14: a += 1
Line 24: while d>=1:
Line 14: a += 1
Line 24: while e>=1:
Line 14: a -= 1
Line 24: while d>=1:
This question is based on the graphic shown below.
Choose the correct output of the given Python code.
True
False
true
Angee
False
Angee
0
1
0
Angee
1
Angee
Which two of the following interface objects cannot have child nodes?
NodeList
ProcessingInstruction
Node
Element
Comment
Which of the following options is not a server socket method?
bind()
listen()
connect()
accept()
What will be the correct output of the following Python code?
List = [5, 2, 3, 4, 2, 6, 2, 2, 2, 1]
print(sum(List)+List.count(1)+len(List)+List.index(2)+List.index(2,2)+min(List)+max(List))
50
51
52
54.5
52.4
This question is based on the graphic shown below.
Find the output of the python code given in Figure 1 of the image and choose the correct answer from the options given in Figure 2 of the same image.
(i)
(ii)
(iii)
What will be the correct output of the following Python code?
x = 5.2
x **= 3
print(x)
125
140.608
45
15.602
What will be the correct output of the following Python code?
import bisect
# initializing list
li = [1, 3, 4, 4, 4, 6, 7]
print ("Output = ", end="")
print (bisect.bisect(li, 4)+bisect.bisect_left(li, 4)+bisect.bisect_right(li, 4, 0, 4))
Output = 10
Output = 11
Output = 12
Output = 13
What will be the correct output of the following Python code?
def f():
print (s)
s = "Me too."
print (s)
s = "Hi"
f()
print (s)
Hi
Me Too.
Hi
Me Too.
Hi
Me Too.
Hi
Hi
Code will give a compilation error.
Which of the given shell expressions in Python 3.4.2 will give an error?
>>>'hi';
>>>'hello';
>>>Good morning;
>>>''Good evening'';
This question is based on the graphic shown below.
What will be the correct output of the given Python code?
dasyunr12
rnuysad12
dasyonr6
rnoysadI6
Which of the following lines of code results in a compilation error?
1. c1 = { 'A' : 'B', 'C' : 19 }
2. c2 = { 'ID' , 47 }
3. sequ = ('A', 'C', 'D')
4. c1.update(c2)
5. print (str(c1))
6. ct = dict.fromkeys(sequ,5)
7. print (str(ct))
Line number 1
Line number 2
Line number 4
Line number 6
This question is based on the graphic shown below.
What will be the output of the given Python code?
first= Ajay , Second: 100000
first= Amit , Second: 200000
first= Ajay , Second: 100000
first= Amit , Second: 200000
value = 2
first= Ajay , Second: 100000
first= Amit , Second: 200000
value = 3
It will give an error.
What will be the output of the following program?
def country(*abc):
if len(abc) == 1:
item = abc[0]
def f(obj):
return obj[item]
else:
def f(obj):
return tuple(obj[item] for item in abc)
return f
selection = []
selection = country(slice(2, None))('AUSTRALIA')
print (selection)
AU
USTARLIA
STRALIA
ALIA
Find the output of the following Python code and choose the correct answer from the given options.
ast = [2, 1, 3, 5, 3, 8]
ast.sort()
print (end="")
for i in range(0, len(ast)):
print(ast[i]*2, end=" ")
print("\r")
ast.reverse()
print (end="")
for i in range(1, len(ast)):
print(ast[i]+3, end=" ")
2 4 6 6 10 16
8 6 6 5 4
2 4 6 6 10 16
11 8 6 6 5 4
1 2 3 3 5 8
11 8 6 6 5 4
2 4 6 6 10 16
8 6 6 5 4 2
This question is based on the graphic shown below.
Consider the Python code in Figure 1 of the given image and choose its correct output from Figure 2.
(a)
(b
(c)
This question is based on the graphic shown below.
In Python 3.4.2 shell, what will be the output of the given code?
[-1, 435, 1123.5, 5678.2]
[-1, 1123.5, 5678.2]
[-1, 1, 5678.2]
[-1, 1, 1123.5, 5678.2]
Which two of the following dictionary objects return "0" on success and "-1" on failure?
int PyDict_SetItem(PyObject *p, PyObject *key, PyObject *val)PyObject*
PyDict_GetItemWithError(PyObject *p, PyObject *key)
PyObject* PyDict_New()
int PyDict_DelItemString(PyObject *p, const char *key)
This question is based on the graphic shown below.
If the id's of 'a1', 'a2' and 'a3' in the given Python code are 3012123901, 3012123902 and 3012123903 respectively, then what will be the output of the code?
3012123901 3012123901 3012123901
ajus angee
3012123901 3012123902 3012123901
ajus angee
ajus angee
ajus angee
ajus angee
ajus angee
In which of the following modes of files, the 'tell()' function returns an opaque number that gives the current position of the file object?
binary mode
text mode
both binary and text modes
This question is based on the graphic shown below.
Analyse the Python code given in Figure 1 of the image and choose the correct answer from the options given in Figure 2 of the same image.
(i)
(ii)
(iii)
(iv)
Analyse the given Python code and answer the question that follows.
import math
a = -10
b = 5.5
c = 15
d = 5
print (math.copysign(6.5, -10))
print (end="")
print (math.gcd(5,15))
What will be the correct output of the above Python code?
-4.5
5
-5.5
10
-6.5
5
-6.5
10
In Python, which of the following options is the correct exception that is raised when the next() method of an iterator does not point to any object?
SystemExit
StandardError
StopIteration
None of the above.
What will be the correct output of the following Python code?
class X(object):
def __init__(self,a):
self.num = a
def dbup(self):
self.num *= 2
class Y(X):
def __init__(self,a):
X.__init__(self, a)
def tpup(self):
self.num*= 3
obj = Y(4)
print(obj.num*2/1)
obj.dbup()
print(obj.num*3/2)
obj.tpup()
print(obj.num/2*3)
6.0
12.0
34.0
8.0
12.0
36.0
8.0
12.0
34.0
6.0
12.0
36.0
Which of the following modules are used with the FTP protocol in Python?
ftplib
smtplib
urllib
httplib
What will be the correct output of the following Python language code?
import multiprocessing
result = []
def s_p(mp):
global result
for num in mp:
result.append(num * num+1)
print("{}".format(result))
if __name__ == "__main__":
mp = [1,2,3,4]
p1 = multiprocessing.Process(target=s_p, args=(mp,))
p1.start()
p1.join()
print("{}".format(result))
[2, 5, 10, 17]
[]
[2, 5, 10, 17]
[1, 2, 3, 4, 2, 5, 10, 17]
[1, 2, 3, 4, 2, 5, 10, 17]
[]
What will be the correct output of the following Python code?
def abc(n):
if n <= 1:
return n
else:
return(abc(n-1) + abc(n-2))
print("1")
nterms = 13
if nterms <= 0:
print("0")
else:
for i in range(nterms):
x=abc(i)
print(x+11)
0
1
155
177
Find the output of the following Python code and choose the correct answer from the given options.
import multiprocessing
def enr(conn, msgs):
for msg in msgs:
conn.send(msg)
print("{}".format(msg))
conn.close()
def cer(conn):
while 1:
msg = conn.recv()
if msg == "Hi":
break
print("{}".format(msg))
if __name__ == "__main__":
msgs = ["hello", "hey", "hru?", "Hi"]
parent_conn, child_conn = multiprocessing.Pipe()
p1 = multiprocessing.Process(target=enr, args=(parent_conn,msgs))
p2 = multiprocessing.Process(target=cer, args=(child_conn,))
p1.start()
p2.start()
p1.join()
p2.join()
hello
hey
hru?
hello
Hi
hru?
hello
hey
hru?
hello
hey
hru?
Hi
hello
hey
hru?
Hi
hello
hey
hru?
Code will give a compilation error.
Which of the given tuples are not used in the AF_INET6 address family?
sockaddr
host
groups
port
pid
In Python, while developing a program, if you know the place where the code is to be written, but at a later stages, then which of the following control statements will you use?
Pass statement
Break statement
Continue statement
Either a or c
Which of the following databases can be used with Python?
1. MySQL
2. Oracle
3. Maria DB
4. Microsoft SQL Server
All options 1, 2, 3, and 4.
Only options 1 and 4.
Only options 1, 2, and 4.
Only options 2, 3, and 4.
This question is based on the graphic shown below.
What will be the correct output of the given Python 3.4.2 code?
No exception
No exception
No exception
No exception
No exception
No exception
division by zero!
No exception
division by zero!
No exception
No exception
Analyse the given Python code and answer the question that follows.
def prt2(n):
y=0
k = 2*n - 2
for i in range(0, n):
for j in range(0, k):
print(end=" ")
k = k - 2
for j in range(0, i+1):
y=y+k
return(y)
def prt3(m):
if m > 1:
for i in range(2,m):
if (m % 3) == 0:
print("failure")
break
else:
print("success")
else:
print("failure")
n = 5
m=prt2(n)
k=prt3(m-3)
How many times the word "success" will be printed in the output, when the above code is executed?
2
3
4
5
Analyse the following Python code and choose the correct answer from the given options.
class D:
def __init__(self, l, c):
self.l = l
self.c = c
def b(self):
b = "1" * 2
return b
if __name__ == "__main__":
d = D(4, "0")
b = d.b()
print(b)
10
01
11
00
While working with MySQL database in Python, which of the following statements is/are correct about the fetchone() method?
1. It is used for fetching the next row of a query result set.
2. It is used for returning the number of rows that were affected by an execute() method.
3. It is used for fetching only the first or the last row of a query result set.
Only option 1.
Only option 2.
Only option 3
Only options 2 and 3.
Select the correct output of the following Python code from the given options.
class St:
stm = 'Y'
stm = 'X'
def __init__(self, r):
self.r = r
def setdd(self, dd):
self.dd = dd
def getdd(self):
return self.dd
a = St(101)
a.setdd("Y, UP")
a.setdd("X")
print(a.getdd())
X
Y, UP
X
Y, UP
Code will give a compilation error.
What will be the correct output of the given Python code?
tuple1 = (0 ,1, 2, 3)
print(tuple1[1:])
print(tuple1[::-1])
print(tuple1[2:4])
(0, 1, 2, 3)
(3, 2, 1, 0)
(3)
(0, 1, 2, 3)
(3)
(2, 3)
(1, 2, 3)
(3, 2, 1, 0)
(2, 3)
No output will be displayed.
This question is based on the graphic shown below.
Choose the correct output of the given Python 3.4 code.
Hello ajus
I am good
Hello angee
How are you?
val : 30
Hello ajus
I am good
Hello angee
How are you?
val : 25
Hello ajus
I am good
How are you?
val :30
Hello ajus
I am good
How are you?
val : 25
What would be the output of the Python code given in the image?
JammyPython 3.4.2 # 1siera
RPython 3.4.2 # 2siera
SPython 3.4.2 # 3siera
JammyPython 3.4.2 # 1John
PPython 3.4.2 # 2John
QPython 3.4.2 # 3John
JammyPython 3.4.2 # 1siera
PPython 3.4.2 # 2John
QPython 3.4.2 # 3John
JammyPython 3.4.2 # 1John
RPython 3.4.2 # 2siera
SPython 3.4.2 # 3siera
JammyPython 3.4.2 # 1siera
PPython 3.4.2 # 2siera
QPython 3.4.2 # 3siera
JammyPython 3.4.2 # 1John
RPython 3.4.2 # 2John
SPython 3.4.2 # 3John
JammyPython 3.4.2 # 1siera
RPython 3.4.2 # 2John
SPython 3.4.2 # 3John
JammyPython 3.4.2 # 1John
PPython 3.4.2 # 2siera
QPython 3.4.2 # 3siera
What will be the correct output of the following Python code?
def abc():
y = 2018
if (y % 4) == 0:
if (y % 100) == 0:
if (y % 400) == 0:
print("0")
else:
print("1")
else:
print("0")
else:
print("1")
abc()
0
1
0
1
1
0
What will be the correct output of the following Python language code?
def ps(a,b = 2):
return a + b
a=8
s1 = 1
i = 1
while i <= a:
s1 = s1 + i *2
i = i+1
print(ps(a=1) + ps(a=1, b=3)+s1)
60
80
74
90
Code will give a compilation error.
What will be the correct output of the following Python code?
lstx = range(1, 11)
print(lstx)
lst1_x5 = lstx[1 : 5]
print (lst1_x5)
lst5_x = lstx[5 : 8]
print (lst5_x)
lst1_y = lstx[1 : ]
print (lst1_y)
lst_x5 = lstx[: 5]
print (lst_x5)
lst1_8_2 = lstx[1 : 8 : 2]
print (lst1_8_2)
lst_rev = lstx[ : : -1]
print (lst_rev)
lst_rev_9_5_2 = lstx[9 : 4 : -2]
print (lst_rev_9_5_2)
range(1, 10)
range(2, 4)
range(6, 8)
range(2, 10)
range(1, 5)
range(2, 7, 3)
range(11, 0, -1)
range(10, 5, -2)
range(1, 11)
range(2, 5)
range(6, 8)
range(2, 11)
range(1, 5)
range(2, 9, 2)
range(10, 0, -1)
range(10, 5, -2)
range(1, 11)
range(2, 6)
range(6, 9)
range(2, 11)
range(1, 6)
range(2, 9, 2)
range(10, 0, -1)
range(10, 5, -2)
No output will be displayed.
Find the output of the following Python code and choose the correct answer from the given options.
m = 7
tor = 1
if m < 0:
print("0")
elif m == 0:
print("1")
else:
for i in range(1,m + 1):
tor = tor*i
print(tor)
5260
4842
5040
4920
Find the output of the following Python code and choose the correct answer from the given options.
class St:
stm = 'B'
def __init__(self, n, r):
self.n = n
self.r = r
a = St("D", 3)
print (a.stm)
St.stm = "D"
b = St("A", 4)
print (a.stm)
print (b.stm)
B
D
D
B
D
A
D
D
B
D
A
D
What will be the correct output of the following Python code?
lst = [3, 1, 2, 5, 4, 3, 8]
del lst[2 : 5]
print (end="")
for i in range(0, len(lst)):
print(lst[i]+1, end=" ")
print("\r")
lst.pop(2)
print (end="")
for i in range(0, len(lst)):
print(lst[i]+2, end=" ")
2 1 2 4
5 3 8
4 2 4 9
5 3 10
4 1 4 9
5 4 10
2 1 2 6
4 2 8
This question is based on the graphic shown below.
What will be the correct output of the given Python code?
[(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')]
[(2, 'two'), (4, 'four'), (1, 'one'), (3, 'three')]
[(3, 'three'), (4, 'four'), (1, 'one'), (2, 'two')]
[(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')]
What will be the correct output of the following Python code?
lis = [11, 22, 33]
lis1 = [14, 5, 6]
lis2= lis + lis1
print (end="")
for i in range(0,len(lis2)):
print (lis2[i]*1, end=" ")
print ("\r")
lis3 = lis * 2
print (end="")
for i in range(0,len(lis3)):
print (lis3[i]+1, end=" ")
11 22 33 14 5 6
12 23 34 12 23 34
11 22 33 14 5 6
11 22 33 11 22 33
11 22 33 14 5 6
14 5 6 12 23 34
No output will be displayed.
What will be the correct output of the following Python code?
def p_ft(x):
for i in range(1, x + 1):
if x % i == 0:
d=6/2+i
print(d+9)
n = 42
p_ft(n)
52.0
54.0
56.0
58.0
What will be the correct output of the following Python code?
def hello():
print("0")
return("1")
def hello2():
print("0")
hello() * 2
hello2()
0
0
0
1
0
1
0
0
0
1
Find the correct output of the following Python code.
def req(str):
p=2
str = str.split()
str2 = []
for i in str:
if i not in str2:
str2.append(i)
for i in range(0, len(str2)):
p=str.count(str2[i])+p
print(p)
def main():
str ='apple mango apple orange orange apple guava mango mango'
req(str)
if __name__=="__main__":
main()
10
11
12
14
What will be the correct output of the following Python code?
value = [2, 3, 4, 5, 6]
cd = 0
try:
cd = value[3]
except IndexError:
print('0', end = '')
except:
print('1', end = '')
finally:
print('0', end = '')
cd = 10
try:
cd = cd/0
except ZeroDivisionError:
print('1', end = '')
finally:
print('0')
001
110
100
010
Upon creation of the 'dumbdbm' database, files with which of the given extensions are created?
.dat
.dbm
.bin
.dir
Choose the correct output of the following Python code from the given options.
set1 = set()
set2 = set()
for i in range(2, 6):
set1.add(i)
for i in range(4, 7):
set2.add(i)
print("Set1 = ", set1)
print("Set2 = ", set2)
set3 = set1 | set2
set4 = set1 & set2
print(set4)
if set3 > set4:
print("0")
elif set3 < set4:
print("2")
else :
print("1")
if set4 < set3:
print("0")
set5 = set3 - set4
print(set5)
if set4.isdisjoint(set5):
print("1")
set5.clear()
print(set5)
Set1 = {2, 3, 4, 5}
Set2 = {4, 5, 6}
{4, 5}
0
0
{2, 3, 6}
1
set()
Set1 = {2, 3, 4, 5, 6}
Set2 = {4, 5, 6, 7}
{4, 5}
0
0
{2, 3, 6}
1
set()
Set1 = {2, 3, 4, 5}
Set2 = {4, 5, 6}
{4, 5}
1
0
{2, 3, 6}
0
set()
Set1 = {2, 3, 4, 5, 6}
Set2 = {4, 5, 6, 7}
{4, 5}
1
{2, 3, 6}
1
0
set()
What will be the correct output of the following Python code?
a = 1
def f():
print (a+2)
def g():
a = 2
print (a+1)
def h():
global a
a = 3
print (a+3)
print (a+4)
f()
print (a+2)
g()
print (a+1)
h()
print (a+2)
3
2
6
5
5
3
3
5
3
3
3
2
6
5
5
3
3
2
6
5
2
Code will give a compilation error.
Find the output of the following Python code and choose the correct answer from the options given below.
tp1 = ('Python',)
m = 5
for i in range(int(m-1)):
tp1 = (tp1,)
print(tp1)
(('Python',),)
((('Python',),),)
(((('Python',),),),)
((((('Python',),),),),)
(('Python',),)
((('Python',),),)
(((('Python',),),),)
((((('Python',),),),),)
(((((('Python',),),),),),)
('Python',)
('Python',)
('Python',)
('Python',)
('Python',)
('Python')
('Python')
('Python')
('Python')
In relation to the socket module in Python-Network programming, which of the following options are the valid values for a socket_type parameter of the socket() function?
SOCK_STREAM
AF_INET
AF_UNIX
SOCK_DGRAM
This question is based on the graphic shown below.
Analyse the Python code in the given image and select the correct line number from the options that will give a compilation error.
Line number 6
Line number 9
Line number 13
Line number 15
What will be the correct output of the following Python code?
import math
a = 3.4536
print ("Result = ",end="")
print (math.trunc(a)+math.ceil(a)+math.floor(a))
Result = 8
Result = 9
Result = 10
Result = 12
Find the output of the following Python code and choose the correct answer from the given options.
class ErrorInCode(Exception):
def __init__(self, data):
self.data = data
def __str__(self):
return repr(self.data)
try:
raise ErrorInCode(1000)
except ErrorInCode as ae:
print ("0",ae.data)
finally:
print ("1")
0
0 1000
1
1000
1
0 1000
1
This question is based on the graphic shown below.
What will be the output of the given Python code?
Hi
Hello
Hi
Hi
Hi
Hello
Hi
Hi
Hi
Hello
Hello
Hello
What will be the correct output of the following Python code?
class Son(object):
def __init__(self, n):
self.n = n
def gN(self):
return self.n
def sE(self):
return False
class Ploy(Son):
def __init__(self, n, eid):
super(Ploy, self).__init__(n)
self.empID = eid
def sE(self):
return True
def gID(self):
return self.empID
emp = Ploy("1", "0")
print(emp.gN(), emp.sE(), emp.gID())
0 True 1
1 False 0
1 True 0
0 False 1
What will be the correct output of the following Python code?
def ps(a,b):
s = a + b
return (s, a)
s, a = ps(0,4)
a=a+4
s1 = 1
i = 1
while i <= a:
s1 = s1 + i
i = i+1
print(s1)
9
10
11
14
Select the correct output of the following Python code from the given options.
import collections
c1 = { 'a' : 1, 'b' : 2 }
c2 = { 'b' : 3, 'c' : 4 }
c3 = { 'f' : 5 }
ch = collections.ChainMap(c1, c2)
#print (ch.maps)
ch1 = ch.new_child(c3)
#print (ch1.maps)
print (ch1['b'])
ch1.maps = reversed(ch1.maps)
print (ch1['b'])
2
3
2
2
3
3
3
2
What will be the correct output of the following Python code?
print (5/2)
print (-5/2)
print (5.0/2)
print (-5.0/2)
2
2
2.5
2.5
2
-2
2.5
-2.5
2.5
-2.5
2.5
-2.5
Code will give a compilation error.
What will be the correct output of the following Python code?
try:
a=10
print (a-9)
raise NameError("0")
except NameError as e:
print ("1")
print (e)
finally:
print ("0")
0
1
1
0
1
0
0
1
1
0
1
0
1
1
0
0
This question is based on the graphic shown below.
What would be the output of the given Python code?
8
10
12
18
This question is based on the graphic shown below.
Which of the following options will be the correct output of the given Python code?
512
0.125
b'ANGEE'
[(1.0, -8.0), (-15.625, 27.0), (74.08800000000001, 15.625)]
512
0.125
b'ANGEE'
[(1.0, 4.0), (6.25, 9.0), (17.64, 6.25)]
b'ANGEE'
[(1.0, 4.0), (6.25, 9.0), (17.64, 6.25)]
512
0.125
b'ANGEE'
[(1.0, -8.0), (-15.625, 27.0), (74.08800000000001, 15.625)]
512
0.125
Find the output of the following Python code and choose the correct answer from the given options.
double = lambda x: x * 2
mt = [1, 5, 4, 6, 8, 11, 3, 12]
ns = list(filter(lambda x: (x%2 == 0) , mt))
print(double(6))
print(ns)
12
[0, 4, 6, 8, 12]
12
[4, 6, 8, 10, 12]
12
[4, 6, 8, 12]
Code will give a compilation error.
Which of the following shell expressions will give the result as an integer value?
1. >>> (100 - 4 x 5) / (20 - 2 x 5)
2. >>> 7.0 / 4
3. >>> 5 / 4
4. >>> 2 x 4 / 2
5. >>> 5 - 2
Line number 1
Line number 2
Line number 5
Lines number 3 and 5
Which of the following Python 3.4.2 shell expressions will produce the below-given output?
56.25
>>>7.5^2
>>>7.5#2
>>>7.5**2
>>>7.5 ! 2
Find the output of the following Python code and choose the correct answer from the given options.
def print_f(x):
y=0
for i in range(1, x + 1):
if x % i == 0:
y=y+i+1
print(y)
num = 32
print_f(num)
63
66
69
72
What will be the correct output of the following Python code?
def part1():
low = 365
up = 372
for num in range(low, up + 1):
order = len(str(num))
s = 0
temp = num
while temp > 0:
digit = temp % 10
s += digit ** order
temp //= 10
if num == s:
print(num)
part1()
365
366
368
369
369
370
370
371
What will be the correct output of the following Python code?
import sys
rList = ['a', 0, 2]
for bn in rList:
try:
print(bn)
r = 1/int(bn)
break
except:
print(sys.exc_info()[0])
print()
print("result",bn,"is",r+2)
a
<class 'ValueError'>
2
result 2 is 2.5 0
<class 'ZeroDivisionError'>
2
result 2 is 2.5
a
<class 'ValueError'>
0
<class 'ZeroDivisionError'>
2
result 2 is 2.5
Code will give a compilation error.
Which of the following statements are correct?
Lists in Python 3.4.2 are immutable.
Tuples in Python 3.4.2 are immutable.
We can use list as a queue in Python 3.4.2.
We cannot use list as a stack in Python 3.4.2.
What will be returned by the following function?
threading.enumerate()
It will return the number of currently alive Thread objects.
It will return a list of all Thread objects.
It will return a list of currently alive Thread objects.
It will return a list of Thread objects that are not alive.
Which of the following options are the correct general socket methods?
s.send()
socket.gethostname()
s.bind()
s.accept()
Which of the following options is a correct syntax of the "AttlistDeclHandler" method?
AttlistDeclHandler(elname, attname, base, required)
AttlistDeclHandler(elname, attname, base, default, systemId)
AttlistDeclHandler(elname, attname, type, base)
AttlistDeclHandler(elname, attname, type, default, required)
What will be the correct output of the following Python language code?
from collections import OrderedDict
od = OrderedDict()
od['a'] = 1
od['b'] = 2
od['c'] = 3
od['d'] = 4
for key, value in od.items():
print("10")
od.pop('c')
for key, value in od.items():
print("01")
od['c'] = 3
for key, value in od.items():
print(key, value+2)
10
10
10
10
01
01
01
a 3
b 4
d 6
c 5
10
10
10
10
01
01
01
01
a 3
b 4
d 5
c 6
10
10
10
10
01
01
01
a 1+2
b 2+2
d 3+2
c 4+2
10
10
10
10
01
01
01
a 1+2
b 2+2
d 4+2
c 3+2
In Python 3.4.2, how many exception statements can you write in a "try" block?
only one exception
two exceptions
three exceptions
multiple exceptions
What will be the output of the following line of code in Python 3.4.2?
>>>print (0xD + 0xB + 0xC)
0
0xD + 0xB + 0xC
0xD0xB0xC
22
36
013011012
1
Error
Fill in the blank.
While working in Python 3.4, sockets are by default created in the _______ mode.
non-blocking
blocking
timeout
What will be the correct output of the following Python code?
a = { 'Name' : 'Harry', 'Age' : 42, 'ID' : 2541997 }
b = [ 1, 3, 5, 6 ]
print (len(a)+len(b))
print (type(a))
print (type(b))
8
<class 'list'>
<class 'dict'>
7
<class 'list'>
<class 'dict'>
8
<class 'dict'>
<class 'list'>
7
<class 'dict'>
<class 'list'>
Which two of the following shell expressions in Python 3.4.2 will give syntax error?
10 * (1/0);
2 + char *3;
while True print('Python');
print('4') + print('4');
while False; print('Python');
This question is based on the graphic shown below.
In the given image, which of the following line numbers in the Python code will result in a compilation error?
Line number 6
Line number 10
Line number 14
Line number 15
Line number 16
In Python 3.4, a conventional pluggable event loop model is provided by which of the following library modules?
selectors
ensurepip
asyncio
enum
Choose the correct output of the following function in Python 3.4.2 shell?
float('-Infinity')
0
1
Infinity
-inf
ValueError:could not convert string to float
What will be the correct output of the following Python code?
num1 = 10
num2 = 14
num3 = 12
if (num1 >= num2) and (num1 >= num3):
lg = num1+4
elif (num2 >= num1) and (num2 >= num3):
lg = num2+5
else:
lg = num3+3
print(lg*3)
45
57
42
59
Fill in the blank:
A lambda function in Python can take __________.
only one argument
only two arguments
only three arguments
any number of arguments
During the execution of the below-given Python/C API function, what will happen when no exception has been raised?
int PyErr_ExceptionMatches(PyObject *exc)
It will return NULL.
A memory access violation will occur.
It will clear the error indicator.
It will call "void PyErr_Print()" function
Find the output of the following Python code and choose the correct answer from the given options.
try :
a = 3
if a < 4 :
b = a/(a-3)
print (b)
except(ZeroDivisionError, NameError):
print ("1")
1.0
0
1
Code will give a compilation error.
What will be the correct output of the following Python code?
class Son(object):
def __init__(self, name):
self.name = name
def gN(self):
return self.name
def sE(self):
return False
class Ply(Son):
def sE(self):
return True
mp = Son("1")
print(mp.gN(), mp.sE())
mp = Ply("0")
print(mp.gN(), mp.sE())
1 False
0 True
0 True
1 False
1 True
0 False
0 False
1 True
Which of the following statements about Python 3.4.2 is/are false?
It is an object-oriented language.
It is not an interpreted language.
It is an interactive language.
It is not a case-sensitive language.
Analyse the following Python code and choose its correct output from the given options.
def comF(x, y):
if x > y:
sm = y
else:
sm = x
for i in range(1, sm+1):
if((x % i == 0) and (y % i == 0)):
cf = i
return cf
num1 = 84
num2 = 64
print(comF(num1, num2))
4
6
2
8
What will be the correct output of the following Python code?
List = [5, 12, 3, 4, 2, 16, 2, 2, 2, 11]
print(sum(List)+List.count(2)+min(List)+max(List)+List.pop())
del List[0]
del List[6]
print(List.pop(0)+len(List)+List.index(2)+List.index(2,2))
62
18
72
18
82
22
Python 3.4 Fiverr Skills Test 2020