Test 02 Rev 01 Flashcards
What does this numerical expression yield?
6*8*4/-6//-4
Answer = 8.0
Calculation = ((((6*8)*4)/-6)//-4)
What does this numerical expressions yield?
10/(5%2)
Answer = 10.0
Calculation = (10/(5%2))
What does this numerical expressions yield?
4+11%6//2**2
Answer = 5
Calculation = (4+((11%6)//(2**2)))
What does this numerical expressions yield?
1*2**(3%2+2)+14//5
Answer = 10
Calculation = (1*2**((3%2)+2))+(14//5)
What does this numerical expressions yield?
3*2**2**(5//7+1)
Answer = 12
Calculation = (3*(2**(2**((5//7)+1))))
What does this boolean expression yield?
’’ or not 0
True
bool(‘’) = False
not 0 = True
⇒ False or True == True
What does this numerical boolean yield?
False or False and True or True or x
True
(((False or False) and True) or True) == True
x is not evaluated
Write a control sequence that …
sets shape to ‘triangle’ or ‘not triangle’ given the lengths of three lines.
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.
Write a loop with the following behaviour:
Generates a list containing the first 64 powers of 2.
Possible Code:
lst = []
for i in range(64):
lst.append(2**i)
Write a loop with the following behaviour:
Generates a list containing all the powers of 2 that are less than 1,000,000.
Possible Code:
lst = []
index = 0 while 2** index < 1000000:
lst = lst + [2** index]
index = index + 1