Complete the code to create a NumPy array of 5 zeros.
import numpy as np arr = np.[1](5) print(arr)
The np.zeros function creates an array filled with zeros.
Complete the code to generate 100 linearly spaced values between 0 and 10.
import numpy as np x = np.[1](0, 10, 100) print(x[:5])
np.linspace generates evenly spaced numbers over a specified interval.
Fix the error in the code to plot a sine wave using Matplotlib.
import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2*np.pi, 100) y = np.sin(x) plt.plot(x, [1]) plt.show()
The plt.plot function needs the y-values to plot against x. Here, y contains the sine values.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension maps each word to its length using len(word). The condition filters words with length greater than 3 using >.
Fill all three blanks to create a dictionary of uppercase words mapped to their lengths if length is greater than 4.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] result = { [1]: [2] for word in words if len(word) [3] 4 } print(result)
The dictionary comprehension uses word.upper() as keys, len(word) as values, and filters words with length greater than 4 using >.