Complete the code to make the test deterministic by fixing the seed.
import random def test_random_number(): random.seed([1]) num = random.randint(1, 10) assert num == 7
Setting the seed to a fixed number like 42 makes the random number generation deterministic.
Complete the code to ensure the test always checks the same output from a function using a fixed seed.
import random def get_random_choice(): random.seed([1]) return random.choice(['apple', 'banana', 'cherry']) def test_choice(): assert get_random_choice() == 'banana'
Using seed 42 ensures the choice is always 'banana' for this test.
Fix the error in the test to make it deterministic by setting the seed correctly.
import random def test_sum(): random.seed([1]) values = [random.randint(1, 5) for _ in range(3)] assert sum(values) == 7
Setting the seed to 42 ensures the random values are the same every time, making the sum predictable.
Fill both blanks to create a deterministic test that filters even numbers from a random list.
import random def test_even_numbers(): random.seed([1]) numbers = [random.randint(1, 10) for _ in range(5)] evens = [num for num in numbers if num [2] 2 == 0] assert evens == [4, 10]
Seed 123 fixes the random numbers. Using '%' checks for even numbers correctly.
Fill all three blanks to create a deterministic test that maps uppercase keys to values greater than 5.
import random def test_filtered_dict(): random.seed([1]) data = {chr(97 + i): random.randint(1, 10) for i in range(4)} filtered = {k[2]: v for k, v in data.items() if v [3] 5} assert filtered == {'A': 7, 'D': 6}
Seed 42 fixes random values. Using .upper() converts keys to uppercase. '>' filters values greater than 5.