6 questions on what this module teaches. Guessing is fine: this is your starting point, not a test. Take the same check again at the end to see what you learned.
1. What does this print? def f(x):
return (x - 2) * (x - 2) + 1
best = min([(f(x), x) for x in range(-3, 6)])
print(best) (1, -3) 1 (2, 1) (1, 2)
2. A learner writes the slope as return f(x + h) - f(x - h) / (2 * h). Why are the answers wrong? It should multiply by (2 * h), not divide Division happens before subtraction, so only f(x - h) gets divided: the rise needs its own brackets h is too small; with a bigger h it would be right Nothing is wrong: Python works from left to right
3. What does this print? import math
p = 0.5 * 0.5 * 0.5
print(round(-math.log(p), 2), round(3 * -math.log(0.5), 2)) 0.13 2.08 -2.08 2.08 2.08 0.69 2.08 2.08
4. What does this print? def dot(a, b):
total = 0
for x, y in zip(a, b):
total += x * y
return total
def linear(x, w):
return [dot(wo, x) for wo in w]
print(linear([2, -1], [[1, 1], [0, 3], [-2, 0]])) [2, 0, -4] -6 [1, 3, 4] [1, -3, -4]
5. What does this print? counts = {'a': 2, 'b': 1, 'c': 1}
total = sum(counts.values())
chances = {}
for k in counts:
chances[k] = counts[k] / total
print(chances['a'], sum(chances.values())) 50.0 100.0 0 0 2 4 0.5 1.0
6. w is a matrix with 10 rows of 4 numbers. For linear(x, w) to work, how long must x be, and how many numbers come out? x has 4 numbers; 40 come out x has 40 numbers; 1 comes out x has 10 numbers; 4 come out x has 4 numbers; 10 come out
Answer all 6 to see your result Your answers are saved with a random id, not your name, so we can see which lessons work. Privacy