Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Simpson's rule function from scipy.integrate.
SciPy
from scipy.integrate import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing trapz instead of simpson.
Using quad which is for adaptive quadrature, not Simpson's rule.
✗ Incorrect
The simpson function is imported from scipy.integrate to perform numerical integration using Simpson's rule.
2fill in blank
mediumComplete the code to calculate the integral of y over x using Simpson's rule.
SciPy
result = simpson(y, [1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing dx instead of x array.
Using axis which is a keyword argument, not positional here.
✗ Incorrect
The second argument to simpson is the x values over which y is sampled.
3fill in blank
hardFix the error in the code to correctly compute the integral with simpson when y is a 2D array along axis 0.
SciPy
integral = simpson(y, x, axis=[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using axis=1 which integrates along columns instead.
Using axis=-1 which is last axis, not axis 0.
✗ Incorrect
When y is 2D and integration is along axis 0, axis=0 must be specified.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.
SciPy
lengths = {word: [1] for word in words if [2] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of len(word) for the value.
Using word > 3 which compares string to int.
✗ Incorrect
The dictionary comprehension maps word to its length (len(word)) and filters words with length > 3.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps uppercase words to their values only if the value is positive.
SciPy
result = [1]: [2] for [3] in data.items() if [2] > 0}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using item instead of k, v in the loop.
Not converting keys to uppercase.
✗ Incorrect
The comprehension maps uppercase keys (k.upper()) to values (v) for key-value pairs (k, v) where value is positive.