Complete the code to generate 5 random numbers from a normal distribution with mean 0 and standard deviation 1.
from scipy.stats import norm samples = norm.[1](loc=0, scale=1, size=5) print(samples)
The rvs method generates random samples from the distribution.
Complete the code to generate 10 random values from a uniform distribution between 0 and 1.
from scipy.stats import uniform samples = uniform.[1](loc=0, scale=1, size=10) print(samples)
The rvs method generates random samples from the uniform distribution.
Fix the error in the code to generate 7 random values from an exponential distribution with rate 2 (lambda=2).
from scipy.stats import expon samples = expon.[1](scale=0.5, size=7) print(samples)
The rvs method is needed to generate random samples. Other methods compute probabilities or quantiles.
Fill both blanks to create a dictionary of word lengths for words longer than 4 characters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] lengths = {word: [1] for word in words if len(word) [2] 4} print(lengths)
We want the length of each word as the value, so len(word) is used. The condition filters words longer than 4 characters, so > is correct.
Fill all three blanks to create a dictionary of uppercase words and their lengths for words shorter than 6 characters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] result = { [1]: [2] for word in words if len(word) [3] 6 } print(result)
The dictionary keys are uppercase words (word.upper()), values are their lengths (len(word)), and the condition filters words shorter than 6 characters (<).