wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python debugging

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Find the output of the code:

# abc.py

def func(n):

return n + 10


func('Hello')

(a)  

2.

Find the output of the code:


nameList = ['Harsh', 'Pratik', 'Bob', 'Dhruv']

print nameList[1][-1]

(a)  

3.

Find the output of the code:

for i in range(2):

print i


for i in range(4,6):

print i

a)

0,1,4,5

b)

0,1,2,4,5,6

c)

0,1,2,3,4,5,6

d)

2,4,6

4.

Find the output of the code:

geekCodes = [1, 2, 3, 4]

geekCodes.append([5,6,7,8])

print len(geekCodes)

a)

4

b)

5

c)

6

d)

8

5.

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

a)

10

b)

11

c)

12

d)

13

6.

What is the output of the code:

d1 = {"john":40, "peter":45}

d2 = {"john":466, "peter":45}

print d1 > d2

a)

True

b)

False

c)

Not applicable

7.

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])]]])

a)

2

b)

3

c)

'2'

d)

Key error

8.

Find the output of the code:

D = dict()

for i in range (3):

for j in range(2):

D[i] = j

print(D)

a)

{0: 0, 1: 0, 2: 0}

b)

{0: 1, 1: 1, 2: 1}

c)

{0: 0, 1: 0, 2: 0, 0: 1, 1: 1, 2: 1}

d)

TypeError: Immutable object

9.

Find the output of the code:

List = [True, 50, 10]

List.insert(2, 5)

print(List, "Sum is: ", sum(List))

a)

[True, 50, 10, 5] Sum is: 66

b)

[True, 50, 5, 10] Sum is: 65

c)

TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’

d)

[True, 50, 5, 10] Sum is: 66

10.

Find the output of the code:

L = list('123456')

L[0] = L[5] = 0

L[3] = L[-2]

print(L)

a)

[0, ‘2’, ‘3’, ‘4’, ‘5’, 0]

b)

[‘6’, ‘2’, ‘3’, ‘5’, ‘5’, ‘6’]

c)

[‘0’, ‘2’, ‘3’, ‘5’, ‘5’, ‘0’]

d)

[0, ‘2’, ‘3’, ‘5’, ‘5’, 0]