Complete the code to generate 5 random numbers from a uniform distribution between 0 and 1.
import numpy as np samples = np.random.[1](5)
The np.random.rand function generates random samples from a uniform distribution over [0, 1).
Complete the code to generate 10 random integers between 1 and 100 (inclusive).
import numpy as np ints = np.random.[1](1, 101, 10)
The np.random.randint function generates random integers from low (inclusive) to high (exclusive). Here, 101 is used to include 100.
Fix the error in the code to generate 7 random samples from a normal distribution with mean 0 and standard deviation 1.
import numpy as np samples = np.random.normal([1], 1, 7)
The mean of the normal distribution should be 0, not 1 or 7.
Fill both blanks to create a dictionary with words as keys and their lengths as values, but only include words longer than 4 characters.
words = ['apple', 'dog', 'banana', 'cat', 'grape'] lengths = {word: [1] for word in words if [2]
The dictionary comprehension uses len(word) for values and filters words with length greater than 4.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, including only words longer than 3 characters.
words = ['tree', 'sun', 'flower', 'sky'] result = { [1]: [2] for w in words if [3] }
The dictionary comprehension uses uppercase words as keys, their lengths as values, and filters words longer than 3 characters.