Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add two numpy arrays element-wise.
NumPy
import numpy as np arr1 = np.array([1, 2, 3]) arr2 = np.array([4, 5, 6]) result = arr1 [1] arr2 print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' causes subtraction.
Using '*' multiplies elements instead of adding.
Using '/' divides elements instead of adding.
✗ Incorrect
Using the + operator between two numpy arrays adds their elements one by one.
2fill in blank
mediumComplete the code to multiply two numpy arrays element-wise.
NumPy
import numpy as np arr1 = np.array([2, 4, 6]) arr2 = np.array([3, 5, 7]) result = arr1 [1] arr2 print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' adds elements instead of multiplying.
Using '-' subtracts elements instead of multiplying.
Using '/' divides elements instead of multiplying.
✗ Incorrect
The '*' operator multiplies elements of two numpy arrays one by one.
3fill in blank
hardFix the error in the code to subtract two numpy arrays element-wise.
NumPy
import numpy as np arr1 = np.array([10, 20, 30]) arr2 = np.array([1, 2, 3]) result = arr1 [1] arr2 print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' adds elements instead of subtracting.
Using '*' multiplies elements instead of subtracting.
Using '/' divides elements instead of subtracting.
✗ Incorrect
The '-' operator subtracts elements of two numpy arrays one by one.
4fill in blank
hardFill both blanks to create a dictionary with words as keys and their lengths if length is greater than 3.
NumPy
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word' instead of 'len(word)' for the dictionary value.
Using '<' instead of '>' in the condition.
Not using len() to get word length.
✗ Incorrect
We use len(word) to get the length and '>' to filter words longer than 3 letters.
5fill in blank
hardFill all three blanks to create a dictionary with uppercase words as keys and their lengths if length is greater than 4.
NumPy
words = ['apple', 'bat', 'carrot', 'dog'] result = [1] [2] for word in words if len(word) [3] 4 print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list comprehension instead of a dictionary comprehension.
Not converting words to uppercase for keys.
Using '<' instead of '>' in the condition.
✗ Incorrect
We create keys as uppercase words, values as their lengths, and filter words longer than 4.