Certified Associate in Python Programming (PCAP-31-03) — Question 95

Assuming that the code below has been executed successfully, which of the following expressions will always evaluate to True? (Choose two.)

import random

random.seed(1)
v1 = random, random()
random.seed(1)
v2 = random.random()

Answer options

Correct answer: C, D

Explanation

Option C is correct because random.choice([1,2,3]) will always return a value from the list, which is guaranteed to be either 1, 2, or 3, thus it will always be greater than or equal to 1. Option D is also correct since both v1 and v2 are assigned the same random value after setting the seed, ensuring they are equal. Options A and B are incorrect as they do not hold true under the given conditions.