Complete the code to generate a random integer between 1 and 10 using numpy.
import numpy as np random_number = np.random.[1](1, 11) print(random_number)
The integers function from np.random generates random integers in a specified range. Here, it generates an integer from 1 (inclusive) to 11 (exclusive), so between 1 and 10.
Complete the code to generate 5 random integers between 0 and 20 using numpy.
import numpy as np random_numbers = np.random.[1](0, 20, size=5) print(random_numbers)
The integers function can generate multiple random integers by specifying the size parameter. Here, it generates 5 integers from 0 (inclusive) to 20 (exclusive).
Fix the error in the code to generate a random integer between 5 and 15 using numpy integers().
import numpy as np random_num = np.random.integers([1], 15) print(random_num)
The integers function requires the first argument as the low (inclusive) and the second as high (exclusive). Here, 15 is the exclusive upper bound, so the low should be 5.
Fill both blanks to create a dictionary with words as keys and their lengths as values, only for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension uses len(word) to get the length of each word. The condition len(word) > 3 filters words longer than 3 characters.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = { [1]: [2] for word in words if len(word) [3] 3} print(lengths)
The dictionary keys are uppercase words using word.upper(). The values are the lengths using len(word). The condition filters words longer than 3 characters with >.