Test 02 Rev 01 Flashcards

1
Q

What does this numerical expression yield?

6*8*4/-6//-4

A

Answer = 8.0

Calculation = ((((6*8)*4)/-6)//-4)

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

What does this numerical expressions yield?

10/(5%2)

A

Answer = 10.0

Calculation = (10/(5%2))

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

What does this numerical expressions yield?

4+11%6//2**2

A

Answer = 5

Calculation = (4+((11%6)//(2**2)))

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

What does this numerical expressions yield?

1*2**(3%2+2)+14//5

A

Answer = 10

Calculation = (1*2**((3%2)+2))+(14//5)

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

What does this numerical expressions yield?

3*2**2**(5//7+1)

A

Answer = 12

Calculation = (3*(2**(2**((5//7)+1))))

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

What does this boolean expression yield?

’’ or not 0

A

True

bool(‘’) = False

not 0 = True

⇒ False or True == True

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

What does this numerical boolean yield?

False or False and True or True or x

A

True

(((False or False) and True) or True) == True

x is not evaluated

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

Write a control sequence that …

sets shape to ‘triangle’ or ‘not triangle’ given the lengths of three lines.

A

Possible Code:

x = ?
y = ?
z = ?
if x < y+z and y < x+z and z < x+y:
shape = ‘triangle’
else:
shape = ‘not triangle’

Note: For three lines to make a triangle, every line must be shorter than the sum of the remaining two.

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

Write a loop with the following behaviour:

Generates a list containing the first 64 powers of 2.

A

Possible Code:

lst = []
for i in range(64):
lst.append(2**i)

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

Write a loop with the following behaviour:

Generates a list containing all the powers of 2 that are less than 1,000,000.

A

Possible Code:

lst = []
index = 0 while 2** index < 1000000:
lst = lst + [2** index]
index = index + 1

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