Font size
WorksheetsPython debugging
Total questions: 10
Worksheet time: 5mins
Find the output of the code:
# abc.py
def func(n):
return n + 10
func('Hello')
(a)
Find the output of the code:
nameList = ['Harsh', 'Pratik', 'Bob', 'Dhruv']
print nameList[1][-1]
(a)
Find the output of the code:
for i in range(2):
print i
for i in range(4,6):
print i
0,1,4,5
0,1,2,4,5,6
0,1,2,3,4,5,6
2,4,6
Find the output of the code:
geekCodes = [1, 2, 3, 4]
geekCodes.append([5,6,7,8])
print len(geekCodes)
4
5
6
8
Find the output of the code:
check1 = ['Learn', 'Quiz', 'Practice', 'Contribute']
check2 = check1
check3 = check1[:]
check2[0] = 'Code'
check3[1] = 'Mcq'
count = 0
for c in (check1, check2, check3):
if c[0] == 'Code':
count += 1
if c[1] == 'Mcq':
count += 10
print count
10
11
12
13
What is the output of the code:
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
print d1 > d2
True
False
Not applicable
Find the output of the code:
D = {1 : 1, 2 : '2', '1' : 1, '2' : 3}
D['1'] = 2
print(D[D[D[str(D[1])]]])
2
3
'2'
Key error
Find the output of the code:
D = dict()
for i in range (3):
for j in range(2):
D[i] = j
print(D)
{0: 0, 1: 0, 2: 0}
{0: 1, 1: 1, 2: 1}
{0: 0, 1: 0, 2: 0, 0: 1, 1: 1, 2: 1}
TypeError: Immutable object
Find the output of the code:
List = [True, 50, 10]
List.insert(2, 5)
print(List, "Sum is: ", sum(List))
[True, 50, 10, 5] Sum is: 66
[True, 50, 5, 10] Sum is: 65
TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’
[True, 50, 5, 10] Sum is: 66
Find the output of the code:
L = list('123456')
L[0] = L[5] = 0
L[3] = L[-2]
print(L)
[0, ‘2’, ‘3’, ‘4’, ‘5’, 0]
[‘6’, ‘2’, ‘3’, ‘5’, ‘5’, ‘6’]
[‘0’, ‘2’, ‘3’, ‘5’, ‘5’, ‘0’]
[0, ‘2’, ‘3’, ‘5’, ‘5’, 0]
