Module 1 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What will x be after the following statement?
x = [n**3 for n in range (4)]

a.
[0, 1, 3, 9]

b.
[0,1, 8, 27]

c.
[0, 3, 9, 27]

d.
none of the above

A

b.
[0,1, 8, 27]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which statement is illegal in Python?
a.
x = {(10,), (20,)}

b.
y = {[10],[20]}

c.
z = {10,20}

d.
all are legal

A

b.
y = {[10],[20]}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

x = [10 , 20, 30]
y = x
print(id(x) == id(y))

True or False?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If you wanted to find the standard Euclidean distance between two vectors, you would find the p-norm of their difference, with p equal to what value?
a.
p = 1/2

b.
p = 1

c.
p = infinity

d.
p = 2

A

d.
p = 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which of the following does not exist in Python?
a.
list comprehension

b.
tuple comprehension

c.
set comprehension

d.
dictionary comprehension

A

b.
tuple comprehension

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the output after the following statements of the print?

z = “university”
print (z [::-1][1:4])

a.
“tis”

b.
“isr”

c.
“ive”

d.
“niv”

A

a.
“tis”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

m = {10:20, 30:40}
for x, y in m.items ():
print (x, y, end=” “)
a.
{10:20, 30:40}

b.
10 30 20 40

c.
10:20, 30:40

d.
10 20 30 40

A

d.
10 20 30 40

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the result of the following:
def f(n):
if n==1:
return 1
else:
return 2**n*f(n-1)
print(f(3))

a.
24

b.
16

c.
32

d.
36

A

c.
32

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the output after the following:

x = [[10] , 20]
y = x. copy ()
y [0][0] = 100
print (x, y)

a.
[[10]; 20] [[10]; 20]

b.
[[100]; 20] [[10]; 20]

c.
[[100]; 20] [[100]; 20]

d.
[[10]; 20] [[100]; 20]

A

c.
[[100]; 20] [[100]; 20]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What will be y after the following statement?

x = “Wednesday”
y = x [1:5][100:500] + x [2::4]

a.
error

b.
[“d”, “d”]

c.
“dn”

d.
[“d”, “n”]

e.
“dd”

A

e.
“dd”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly