Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to calculate the square root of 16 using numpy.
NumPy
import numpy as np result = np.[1](16) print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.square() which squares the number instead of finding the root.
Using np.power() without the correct exponent.
✗ Incorrect
The function np.sqrt() calculates the square root of a number.
2fill in blank
mediumComplete the code to calculate the square root of each element in the numpy array.
NumPy
import numpy as np arr = np.array([4, 9, 25]) roots = np.[1](arr) print(roots)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use
np.square() which squares elements instead.Using a non-existent function like
np.root().✗ Incorrect
np.sqrt() works element-wise on numpy arrays to find square roots.
3fill in blank
hardFix the error in the code to correctly compute the square root of 49.
NumPy
import numpy as np value = 49 result = np.[1](value) print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
np.square() which squares the number instead of finding the root.Using
np.pow() without the correct exponent.✗ Incorrect
The correct function to compute square root is np.sqrt().
4fill in blank
hardFill both blanks to create a dictionary with numbers as keys and their square roots as values.
NumPy
import numpy as np numbers = [1, 4, 9, 16] sqrt_dict = { [1]: np.[2](num) for num in numbers } print(sqrt_dict)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong variable name for the key.
Using
np.square() instead of np.sqrt().✗ Incorrect
Use num as the key and np.sqrt() to get the square root values.
5fill in blank
hardFill all three blanks to create a list of square roots for numbers greater than 10.
NumPy
import numpy as np nums = [4, 16, 25, 9, 36] sqrt_list = [np.[1](n) for n in nums if n [2] [3]] print(sqrt_list)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
np.square() instead of np.sqrt().Using wrong comparison operators like '<' or '==' instead of '>'.
Using a wrong number for filtering.
✗ Incorrect
Use np.sqrt() to get square roots, and filter numbers greater than 10 with n > 10.