Python Institute PCAP-31-03 Exam - Topic 3 Question 85 Discussion
Assuming that the code below has been executed successfully, which of the following expressions will always evaluate to True? (Select two answers)import randomv1 = random. random()v2 = random. random()
C) random.choice([1,2,3]) >=1 and D) v1 >= 1
A) len(random.sample([1,2,3],2)) > 2
B) v1 == v2
Python Institute PCAP-31-03 Exam - Topic 3 Question 85 Discussion
Actual exam question for
Python Institute's
PCAP-31-03 exam
Wait, are we supposed to be picking the answers or making funny comments? I'm torn between cracking jokes about the random module and actually trying to solve this problem. Decisions, decisions...
Option D is tempting, but I don't think it's a safe bet. The random.random() function can return any value between 0 and 1, so there's no guarantee that v1 will always be greater than or equal to 1. Gotta think this through carefully.
Haha, option A is a bit of a trap, isn't it? You'd think selecting two random numbers from a list of three would always be less than 2, but I guess the random module has a few surprises up its sleeve.
I'm feeling lucky with option C! Random.choice() will always return one of the values in the list, and they're all greater than or equal to 1, so this should be a guaranteed winner.
Hmm, option B? The random.random() function generates a random float between 0 and 1, so the chance of v1 being equal to v2 is pretty slim. Gotta go with the odds on this one.
Leanna
9 months agoTeddy
9 months agoLonny
9 months agoClarence
10 months agoFelicia
10 months agoVirgie
10 months agoTasia
10 months agoSherman
11 months agoGayla
11 months agoKristel
11 months agoEric
11 months agoGolda
11 months agoFrancine
12 months agoArlene
12 months agoLennie
1 year agoGraciela
1 year agoKara
1 year agoEmmanuel
1 year agoRolande
1 year agoNieves
1 year agoTammara
1 year agoJestine
1 year agoJaime
1 year agoShayne
1 year agoBlythe
1 year agoLuis
1 year agoAltha
1 year agoSharen
1 year agoGearldine
1 year agoJeannetta
1 year agoStanton
1 year agoAmalia
1 year agoEmeline
1 year ago