PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 74


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

Exam PCAP Question 74
Show Answer
Correct Answer: BD

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

9 comments
Sign in to comment
macxszOptions: BD
May 3, 2022

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

palagusOptions: BD
May 25, 2022

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

vlobachevsky
Oct 9, 2021

BD is correct

rocky48
Mar 9, 2022

>>> 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

aferiverOptions: AD
Apr 11, 2023

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.

wacha1978
Oct 17, 2021

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

Noarmy315
Dec 30, 2021

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

Norasit
Apr 25, 2022

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

Jnanada
Aug 19, 2022

The correct answers are B and D