Bird
0
0

What is wrong with this basin-hopping usage?

medium📝 Debug Q7 of 15
SciPy - Advanced Optimization
What is wrong with this basin-hopping usage?
from scipy.optimize import basinhopping

def f(x):
    return (x - 5)**2

result = basinhopping(f, 0, niter='ten')
print(result.fun)
AFunction f must accept two arguments
Bniter must be an integer, not a string
CInitial guess cannot be zero
Dbasinhopping does not have niter parameter
Step-by-Step Solution
Solution:
  1. Step 1: Check niter parameter type

    niter controls number of iterations and must be integer.
  2. Step 2: Identify error

    Passing 'ten' (string) causes type error.
  3. Final Answer:

    niter must be an integer, not a string -> Option B
  4. Quick Check:

    niter type = integer required [OK]
Quick Trick: niter expects integer count, not string [OK]
Common Mistakes:
  • Passing string instead of integer for niter
  • Thinking initial guess can't be zero
  • Assuming function needs two args

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes