Python Libraries MCQ Class 12

 

1. To include the use of functions which are present in the random library, we must use theoption:
a)importrandom
b)random.h
c)import.random
d)random.random

 

2. The output of the following Python code is either 1 or 2.

import random

random.randint(1,2)

a)True
b)False

 

3. What will be the output of the following Python code?

import random

random.choice(2,3,4)

a)An integer other than 2, 3 and 4
b)Either2,3or4
c)Error
d)3only

 

 

4. What will be the output of the following Python code?

import random

random.choice([10.4, 56.99, 76])

a)Error
b)Either 10.4, 56.99 or 76
c) Any number other than 10.4, 56.99 and 76
d)56.99only

 

 

5. What will be the output of the following Python function (random module has already been imported)?

random.choice(‘sun’)

a)sun
b)u
c)eithers,uorn
d)error

 

 

6. What will be the output of the following Python function, assuming that the random module has already been imported?

random.uniform(3,4)

a)Error
b)Either 3 or 4
c) Any integer other than 3 and 4
d) Any decimal value between 3 and 4

 

7. What will be the output of the following Python function if the random module has already been imported?

random.randint(3.5,7)

a)Error
b) Any integer between 3.5 and 7, including 7
c) Any integer between 3.5 and 7, excluding 7
d) The integer closest to the mean of 3.5 and 7

 

8. Which of the following functions helps us to randomize the items of a list?
a)seed
b)randomise
c)shuffle
d)uniform

 

9. What will be the output of the following Python code?

random.seed(3)

random.randint(1,5)

random.seed(3)

random.randint(1,5)

a)3
b)2
c) Any integer between 1 and 5, including 1 and 5
d) Any integer between 1 and 5, excluding 1 and 5

 

10. What is the interval of the value generated by the function random.random(), assuming that the random module has already been imported?
a)(0,1)
b)(0,1]
c)[0,1]
d)[0,1)

 

11. What will be the output of the following Python code?

random.randrange(0,91,5)

a)10
b)18
c)79
d)95

 

12. Both the functions randint and uniform accept ____________ parameters.
a)0
b)1
c)3
d)2

 

13. The randrange function returns only an integervalue.
a)True
b)False

 

14. What will be the output of the following Python code?

random.randrange(1,100,10)

a)32
b)67
c)91
d)80

 

15. What will be the output of the following Python function, assuming that the random library has already been included?

random.shuffle[1,2,24]

a) Randomized list containing the same numbers in any order
b) The same list, that is [1,2,24]
c) A list containing any random numbers between 1 and 24
d) Error

 

16. What the does random.seed(3) return?
a)True
b)None
c)3
d)1

17.Which of the following cannot be returned by random.randrange(4)?
a)0
b)3
c)2.3
d)none of the mentioned

 

18. 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))

 

19. The function random.randint(4) can return only one of the following values. Which?
a)4
b)3.4
c)error
d)5

 

20. 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)

 

21. Which of the following will not be returned byrandom.choice(“1,”)?
a)1
b)(space)
c),
d)none of the mentioned

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

 

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

 

24. Which type of elements are accepted by random.shuffle()?
a)strings
b)lists
c)tuples
d)integers

 

25. What is the range of values that random.random()canreturn?
a)[0.0,1.0]
b)(0.0,1.0]
c)(0.0,1.0)
d)[0.0,1.0)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top