Challenge - 5 Problems
Integer Random Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of numpy integers() with size parameter
What is the output of the following code snippet?
NumPy
import numpy as np np.random.default_rng(seed=42).integers(low=5, high=10, size=3)
Attempts:
2 left
💡 Hint
Remember that integers() generates random integers in [low, high) range.
✗ Incorrect
The integers() method with seed=42 produces the array [7 5 6] for the given parameters.
❓ data_output
intermediate2:00remaining
Shape and values from integers() with 2D size
What is the shape and one possible output of this code?
NumPy
import numpy as np rng = np.random.default_rng(1) rng.integers(0, 3, size=(2, 2))
Attempts:
2 left
💡 Hint
Check the shape parameter and the random seed effect.
✗ Incorrect
With seed=1, integers(0,3,size=(2,2)) produces array([[0, 2], [1, 0]]).
🔧 Debug
advanced2:00remaining
Identify the error in this integers() call
What error does this code raise?
NumPy
import numpy as np rng = np.random.default_rng() rng.integers(low=10, high=5)
Attempts:
2 left
💡 Hint
Check the relationship between low and high parameters.
✗ Incorrect
The high parameter must be greater than low; otherwise, ValueError is raised.
🧠 Conceptual
advanced2:00remaining
Range of values generated by integers()
Which statement about numpy's integers() output range is correct?
Attempts:
2 left
💡 Hint
Think about typical Python range behavior.
✗ Incorrect
numpy's integers() generates integers from low (inclusive) up to but not including high.
🚀 Application
expert3:00remaining
Generate a 1D array of 5 unique random integers between 0 and 9
Which code snippet correctly generates 5 unique random integers between 0 and 9 using numpy's integers()?
Attempts:
2 left
💡 Hint
integers() does not support replace=False, but choice() does.
✗ Incorrect
To get unique integers, use choice() with replace=False. integers() does not have replace parameter.