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

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

Answer options

Correct answer: C

Explanation

The expression C, random.choice([1,2,3]) > 0, will always evaluate to True because the choices are always greater than 0. Option A will not always be true because the length of a sample from the list can only be 1, which is not greater than 2. Option B is incorrect as v1 and v2 are generated randomly and can be equal but are not guaranteed to be. Option D is false because v1 is generated by random.random(), which produces a float between 0.0 and 1.0, so it cannot be greater than 1.