Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q13 of 15
SciPy - Basics and Scientific Computing
What will be the output of this code snippet?
import numpy as np
from scipy import integrate

result = integrate.quad(lambda x: np.exp(-x**2), 0, 1)
print(round(result[0], 4))
A1.0000
B0.7468
C0.5000
DError: integrate.quad not found
Step-by-Step Solution
Solution:
  1. Step 1: Understand the function being integrated

    The function is exp(-x^2), integrated from 0 to 1.
  2. Step 2: Use SciPy's integrate.quad to compute the integral

    integrate.quad returns a tuple; the first element is the integral value. The integral of exp(-x^2) from 0 to 1 is approximately 0.7468.
  3. Final Answer:

    0.7468 -> Option B
  4. Quick Check:

    Integral of exp(-x^2) from 0 to 1 ≈ 0.7468 [OK]
Quick Trick: Remember integrate.quad returns (value, error) tuple [OK]
Common Mistakes:
MISTAKES
  • Confusing the tuple output and printing the whole tuple
  • Using wrong integration limits
  • Expecting exact 1.0 instead of approximate value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes