Challenge - 5 Problems
Random Data Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of random integer generation
What is the output of this code snippet?
Python
import random random.seed(10) print(random.randint(1, 10))
Attempts:
2 left
💡 Hint
The seed fixes the random number sequence.
✗ Incorrect
With seed 10, random.randint(1, 10) returns 7.
❓ Predict Output
intermediate2:00remaining
Output of random choice from list
What is the output of this code snippet?
Python
import random random.seed(3) colors = ['red', 'green', 'blue'] print(random.choice(colors))
Attempts:
2 left
💡 Hint
Seed controls the choice result.
✗ Incorrect
With seed 3, random.choice picks 'red' from the list.
❓ Predict Output
advanced2:00remaining
Output of random.sample with repeated elements
What is the output of this code snippet?
Python
import random random.seed(1) items = [1, 2, 2, 3, 4] sample = random.sample(items, 3) print(sample)
Attempts:
2 left
💡 Hint
random.sample picks unique indices, not unique values.
✗ Incorrect
random.sample picks 3 unique elements by index; duplicates in list are allowed.
❓ Predict Output
advanced2:00remaining
Output of random.choices with weights
What is the output of this code snippet?
Python
import random random.seed(0) items = ['a', 'b', 'c'] weights = [10, 1, 1] result = random.choices(items, weights=weights, k=5) print(result)
Attempts:
2 left
💡 Hint
Weights influence probability but do not guarantee all same picks.
✗ Incorrect
With seed 0 and weights, random.choices returns ['a', 'a', 'b', 'a', 'a'].
🧠 Conceptual
expert2:00remaining
Effect of random.seed on random.random() sequence
Which option correctly describes the output of this code snippet?
Python
import random random.seed(42) values = [round(random.random(), 3) for _ in range(4)] print(values)
Attempts:
2 left
💡 Hint
random.seed fixes the sequence of random.random() calls.
✗ Incorrect
With seed 42, the first four random.random() rounded to 3 decimals are [0.639, 0.025, 0.275, 0.223].