Test Series - python

Test Number 86/108

Q: What the does random.seed(3) return?
A. True
B. None
C. 3
D. 1
Solution: The function random.seed() always returns a None.
Q: Which of the following cannot be returned by random.randrange(4)?
A. 0
B. 3
C. 2.3
D. none of the mentioned
Solution: Only integers can be returned.
Q: Which of the following is equivalent to random.randrange(3)?
A. range(3)
B. random.choice(range(0, 3))
C. random.shuffle(range(3))
D. random.select(range(3))
Solution: It returns one number from the given range.
Q: The function random.randint(4) can return only one of the following values. Which?
A. 4
B. 3.4
C. error
D. 5
Solution: Error, the function takes two arguments.
Q: Which of the following is equivalent to random.randint(3, 6)?
A. random.choice([3, 6])
B. random.randrange(3, 6)
C. 3 + random.randrange(3)
D. 3 + random.randrange(4)
Solution: random.randint(3, 6) can return any one of 3, 4, 5 and 6.
Q: Which of the following will not be returned by random.choice(“1 ,”)?
A. 1
B. (space)
C. ,
D. none of the mentioned
Solution: Any of the characters present in the string may be returned.
Q: Which of the following will never be displayed on executing print(random.choice({0: 1, 2: 3}))?
A. 0
B. 1
C. KeyError: 1
D. none of the mentioned
Solution: It will not print 0 but dict[0] i.e. 1 may be printed.
Q: What does random.shuffle(x) do when x = [1, 2, 3]?
A. error
B. do nothing, it is a placeholder for a function that is yet to be implemented
C. shuffle the elements of the list in-place
D. none of the mentioned
Solution: The elements of the list passed to it are shuffled in-place.
Q: Which type of elements are accepted by random.shuffle()?
A. strings
B. lists
C. tuples
D. integers
Solution: Strings and tuples are immutable and an integer has no len().
Q: What is the range of values that random.random() can return?
A. [0.0, 1.0]
B. (0.0, 1.0]
C. (0.0, 1.0)
D. [0.0, 1.0)
Solution: Any number that is greater than or equal to 0.0 and lesser than 1.0 can be returned.

You Have Score    /10