Complete the code to import the function for minimizing scalar functions.
from scipy.optimize import [1]
The minimize_scalar function from scipy.optimize is used to find the minimum of a scalar function.
Complete the code to define a simple quadratic function to minimize.
def f(x): return (x - [1]) ** 2
This function returns the square of (x - 3). The minimum is at x = 3.
Fix the error in the code to minimize the function f using minimize_scalar.
result = [1](f) print(result.x)
The correct function to minimize a scalar function is minimize_scalar.
Fill both blanks to create a dictionary comprehension that maps numbers to their squares for numbers greater than 2.
squares = {x: x[1]2 for x in range(1, 6) if x [2] 2}The operator ** is used for exponentiation (power). The condition x > 2 filters numbers greater than 2.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths for words longer than 3 characters.
result = {{ { [1] } : [2] for word in words if len(word) [3] 3}}The key is the uppercase word using word.upper(). The value is the length of the word using len(word). The condition len(word) > 3 filters words longer than 3 characters.