QuestionQ92

Modules and Packages

Assuming the code below has executed successfully, which of the following expressions will always evaluate to True?

import random  
  
random.seed(1)  
v1 = random, random()  
random.seed(1)  
v2 = random.random()  
  • A v1 >= 1
  • B len(random.sample([1,2,3],2)) > 2
  • C random.choice([1,2,3]) >= 1
  • D v1 = v2
Explanation

random.choice([1,2,3]) always selects an element from the supplied sequence. Every possible selected value—1, 2, or 3—is greater than or equal to 1. No second choice is true: sampling two items has length 2, and v1 is a tuple whereas v2 is a float.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!