random.random() returns a float that is greater than 0 but less than 1.
v1 = random.random()
v1 will always be less than 1
So B is True
random.choice([1,2,3]) returns 1,2, or 3. which is always greater than 0.
C is True
Ans A, as v1 = 0.054095873573811515, v2 = 0.8975891098469417. So v1 != v2. Then, return False
Ans B, v1 =0.054095873573811515. so v1< 1. Then, return True
Ans C, random.choice([1,2,3]) = 1. So 1 >0. Then, return True
Ans D, len(random.sample([1,2,3],1)) = 1. So 1 < 2. Then, return False
Correct Answer should be B and C
B & C
>>> import random
>>> v1 = random.random()
>>> v2 = random.random()
>>> print(v1)
0.17779831894224019
>>> print(random.choice([1,2,3]))
1
v1 will always be less than 1
random choice will always be one in the list and greater than 0
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
macxsz
Highly Voted 2 years, 6 months agoDezzoPalYeah
Most Recent 1 year, 1 month agodicksonpwc
1 year, 7 months agostuartz
2 years, 5 months ago