Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Tce Code War

Total questions: 15

Worksheet time: 11mins

Name
Class
Date
1.

What is the output of the code ?

def f(x, y=[]):

y.append(x)

return y

print(f(1))

print(f(2))

a)

[1] [2]

b)

[1] [1, 2]

c)

[1, 2] [2]

d)

Error

2.

What is the output of the code?

x = [1, 2, 3]

y = x[:]

y[0] = 99

print(x[0], y[0])

a)

1 99

b)

99 1

c)

99 99

d)

Error

3.

What is the output of code ?

def func(a, b=2, c=3):

print(a, b, c)

func(5, c=10)

a)

5 2 10

b)

5 2 3

c)

5 2 5

d)

error

4.

What is the output of the code below?

a = [1, 2, 3]

print(a * 2)

a)

[1, 2, 3, 1, 2, 3]

b)

[2, 4, 6]

c)

[1, 2, 3, 2]

d)

Error

5.

Choose the output for the code below

print([i for i in range(3)])

print((i for i in range(3)))

a)

[0, 1, 2] [0, 1, 2]

b)

0 1 2

c)

[0, 1, 2] <generator object>

d)

[1 2]

6.

What is the output of the following code?

x = [1, 2, 3]

print(x is x[:])

a)

True

b)

False

c)

Error

d)

1 2 3

7.

Choose the output for the code

a = ([])

for i in range(3):

a.append(i)

print(a)

a)

[1 2 3]

b)

[0 1]

c)

[0, 1, 2]

d)

0 1 2

8.

Choose the output for the code below:

def f():

return [lambda x: i*x for i in range(4)]

funcs = f()

print([m(2) for m in funcs])

a)

[0,2,4,6]

b)

[0, 0, 0, 0,]

c)

[6, 6, 6, 6]

d)

[2 ,2 ,2 ,2]

9.

Choose the output for the code below:

x = {True: "yes", 1: "no", 1.0: "maybe"}

print(x)

a)

{True: 'yes', 1: 'no', 1.0: 'maybe'}

b)

{True: 'no'}

c)

{True: 'yes'}

d)

{True: 'maybe'}

10.

What is the output for the code ?

for i in range(3):

print(i)

else:

print("done")

a)

0 1 2

b)

0 1 2 done

c)

done

d)

0 1

11.

print(0.1 + 0.2 == 0.3)

a)

True

b)

False

c)

Error

d)

0.3

12.

x = "hello"

print(x[::2])

a)

hlo

b)

hel

c)

heo

d)

Error

13.

What is the output for the code below:

x = (1, 2, [3, 4])

x[2].append(5)

print(x)

a)

(1, 2, [3, 4])

b)

(1, 2, [3, 4,5])

c)

[1 ,2 ,3, 4,5]

d)

[1 ,2 ,3, 4,]

14.

Select the output for the code below:

for i in range(3):

try:

if i % 2 == 0:

raise ValueError

else:

print(i)

except:

print("error")

a)

error 1 error

b)

error error error

c)

0 1 2

d)

1 2 3

15.

Select the output for the code below:

x = {[]}

print(len(x))

a)

[]

b)

1

c)

0

d)

Type Error