# Random Function in Python MCQ Class 11-12

## Random Function in Python MCQ Class 11-12

1. What does the following statement do?

import random

a) Imports the random module

b) Imports a random module from a list of modules

c) Imports the random function

d) imports the directory named random

a) Imports the random module

2. What will be the output after the following statements?

import random as rd

print(rd.randint(4,7))

a) A random float value between 4 and 7, including 4 and 7

b) A random float value between 4 and 7, excluding 4 and 7

c) A random integer value between 4 and 7, excluding 4 and 7

d) A random integer value between 4 and 7, including 4 and 7

d) A random integer value between 4 and 7, including 4 and 7

3. What will be the output after the following statements?

import random as rd

print(rd.random())

a) A random float value between 0 and 1

b) A random integer value between 0 and 1

c) A random float value between 0 and 10

d) A random integer value between 0 and 10

a) A random float value between 0 and 1

4. What will be the output after the following statements?

from random import

x = [0, 2, 4, 6, 8, 10]

print(sample(x, 3))

a) A dictionary containing 3 random keys from list x

b) Three random integer values between 0 and 10

c) A list containing 3 random elements from list x

d) A tuple containing 2 random elements from list x

c) A list containing 3 random elements from list x

5. Which of the following can be a possible output after the following statements?

from random import

print(sample(range(0,10), 3))

a) [4, 11, 30]

b) [3, 15, 10]

c) [1, 5, 7, 4]

d) [1, 5, 0]

d) [1, 5, 0]

6. What will be the output after the following statements?

import random

x = [3, 8, 6, 5, 0]

print(random.choice(x))

a) A random element from the list x

b) The list x

c) A random element from the list x, excluding 3 and 0

d) A random element from the list elements 3 and 0

a) A random element from the list x

7. What will be the output after the following statements?

import random

x = [3, 8, 6, 5, 0]

random.shuffle(x)

print(x)

a) A random element from the list x

b) The shuffled list x with the elements mixed up

c) A random element from the list x, excluding 3 and 0

d) A random element from the list elements 3 and 0

b) The shuffled list x with the elements mixed up

8. What will be the output after the following statements?

import random

x = [3, 8, 6, 5, 0]

y = random.shuffle(x)

print(y)

a) A random element from the list x

b) The shuffled list x with the elements mixed up

c) None

d) A random element from the list x, excluding 3 and 0

c) None

9. What will be the output after the following statements?

import random

print(int(random.random()*10))

a) 10

b) A random integer number within the range of 0 to 9

c) None

d) A random floating point number within the range of 0 to 9

b) A random integer number within the range of 0 to 9

10. What will be the output after the following statements?

import random

print(int(random.random()*10) + 1)

a) 11

b) A random integer number within the range of 0 to 11

c) None

d) A random whole number within the range of 1 to 10

d) A random whole number within the range of 1 to 10

11. What will be the output after the following statements?

import random

print(random.sample(range(20), 5))

a) A list of 5 unique numbers within the range of 0 to 19

b) A list of 5 unique numbers within the range of 0 to 20

c) A list of 4 unique numbers within the range of 0 to 19

d) A tuple of 5 unique numbers within the range of 0 to 19

a) A list of 5 unique numbers within the range of 0 to 19

12. What will be the output after the following statements?

import random

print(random.sample(range(5, 20), 4))

a) A list of 5 unique numbers within the range of 4 to 19

b) A list of 5 unique numbers within the range of 5 to 20

c) A list of 4 unique numbers within the range of 5 to 19

d) A tuple of 4 unique numbers within the range of 5 to 19

c) A list of 4 unique numbers within the range of 5 to 19

13. What will be the output after the following statements?

import random

x = [‘Monday’, ‘Tuesday’, ‘Wednesday’, ‘Thursday’, ‘Friday’,

‘Saturday’, ‘Sunday’]

print(x[random.randint(0, len(x) – 1)])

a) IndexError

b) A random day from all the seven days

c) A random day from all the days except Sunday

d) A random day from all the days except Monday

d) A random day from all the days except Monday

14. What is the output of the program given below:

import random

x = random.random()

y= random.randint(0,4)

print(int(x),”:”, y+int(x))

a) 0: 0

b) 2 : 4

c) 1: 6

d) 0 : 5

a) 0: 0

15. To include the use of functions which are present in the random library, we must use the option:

a) import random

b) random.h

c) import.random

d) random.random

a) import random

16. What is the output of the code shown below?

import random

random.choice(2,3,4)

a) An integer other than 2, 3 and 4

b) Either 2, 3 or 4

c) Error

d) 3 only

b) Either 2, 3 or 4

17. What is the output of the function shown below (random module has already been imported)?

>>>random.choice(‘sun’)

a) sun

b) u

c) either s, u or n

d) Error

c) either s, u or n

18. What is the output of the function shown below if the random module has already been imported?

>>>import random

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

b) Any integer between 3.5 and 7, including 7

19. Which type of elements are accepted by random.shuffle()?

a) strings

b) Lists

c) tuples

d) integers

b) Lists

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

import random
random.randint(1,2)

a) True

b) False

c) none

d) Error

a) True