Exam PCAP All QuestionsBrowse all questions from this exam
Question 74

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

    Correct Answer: B, D

    When the seed is set using random.seed(1), it ensures that the sequence of random numbers generated will always be the same. Therefore, random.random() will produce the same output whenever it is called with the same seed. As a result, v1 will always be equal to v2 because they are both generated after setting the seed to 1. This makes v1 == v2 always evaluate to True. Additionally, random.choice([1,2,3]) will always select a number from the list [1,2,3], and since the minimum value in this list is 1, random.choice([1,2,3]) >= 1 will also always be True.

Discussion
macxszOptions: BD

B. v1 == v2 D. random.choice([1,2,3]) >=1

palagusOptions: BD

The correct answers are B and D. A is not correct because pseudorandom numbers are always between 0 and 1.

vlobachevskyOptions: BD

BD is correct

aferiverOptions: AD

It's A and D. random.seed (1) generates always the same secuence of random numbers. random.random() withouth setting the seed value always generates a different number everytime you run the program.

rocky48Options: BD

>>> import random >>> random.seed(1) >>> v1=random.random() >>> random.seed(1) >>> v2=random.random() >>> print(v1>=1) False >>> print(v1==v2) True >>> print(len(random.sample([1,2,3],2)) > 2) False >>> print(random.choice([1,2,3]) >=1) True BD is the answer

JnanadaOptions: BD

The correct answers are B and D

NorasitOptions: BD

B and D random.random() always return value between 0 and 1.

Noarmy315Options: BD

should be BD print(v1>=1) print(v1==v2) print(len(random.sample([1,2,3],2)) > 2) print(random.choice([1,2,3]) >=1) False True False True

wacha1978Options: BD

import random random.seed(1) v1 = random.random() print(v1) random.seed(1) v2 = random.random() print(v2) print(v1==v2) print(len(random.sample([1,2,3],2)) > 2) print(random.choice([1,2,3]) >=1) 0.13436424411240122 0.13436424411240122 True False True