WorksheetsTce Code War
Total questions: 15
Worksheet time: 11mins
What is the output of the code ?
def f(x, y=[]):
y.append(x)
return y
print(f(1))
print(f(2))
[1] [2]
[1] [1, 2]
[1, 2] [2]
Error
What is the output of the code?
x = [1, 2, 3]
y = x[:]
y[0] = 99
print(x[0], y[0])
1 99
99 1
99 99
Error
What is the output of code ?
def func(a, b=2, c=3):
print(a, b, c)
func(5, c=10)
5 2 10
5 2 3
5 2 5
error
What is the output of the code below?
a = [1, 2, 3]
print(a * 2)
[1, 2, 3, 1, 2, 3]
[2, 4, 6]
[1, 2, 3, 2]
Error
Choose the output for the code below
print([i for i in range(3)])
print((i for i in range(3)))
[0, 1, 2] [0, 1, 2]
0 1 2
[0, 1, 2] <generator object>
[1 2]
What is the output of the following code?
x = [1, 2, 3]
print(x is x[:])
True
False
Error
1 2 3
Choose the output for the code
a = ([])
for i in range(3):
a.append(i)
print(a)
[1 2 3]
[0 1]
[0, 1, 2]
0 1 2
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])
[0,2,4,6]
[0, 0, 0, 0,]
[6, 6, 6, 6]
[2 ,2 ,2 ,2]
Choose the output for the code below:
x = {True: "yes", 1: "no", 1.0: "maybe"}
print(x)
{True: 'yes', 1: 'no', 1.0: 'maybe'}
{True: 'no'}
{True: 'yes'}
{True: 'maybe'}
What is the output for the code ?
for i in range(3):
print(i)
else:
print("done")
0 1 2
0 1 2 done
done
0 1
print(0.1 + 0.2 == 0.3)
True
False
Error
0.3
x = "hello"
print(x[::2])
hlo
hel
heo
Error
What is the output for the code below:
x = (1, 2, [3, 4])
x[2].append(5)
print(x)
(1, 2, [3, 4])
(1, 2, [3, 4,5])
[1 ,2 ,3, 4,5]
[1 ,2 ,3, 4,]
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")
error 1 error
error error error
0 1 2
1 2 3
Select the output for the code below:
x = {[]}
print(len(x))
[]
1
0
Type Error
