0% found this document useful (0 votes)
69 views2 pages

Random Module Questions

The document contains a series of questions related to the outputs of Python code using the random module. Each question asks for possible outputs based on random selections, along with the maximum values for certain variables. The questions cover various scenarios involving lists and random integer generation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views2 pages

Random Module Questions

The document contains a series of questions related to the outputs of Python code using the random module. Each question asks for possible outputs based on random selections, along with the maximum values for certain variables. The questions cover various scenarios involving lists and random integer generation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

RANDOM MODULE OUTPUT BASED QUESTIONS:

Q1. What possible output(s) are expected to be displayed at the time of execution of the
following code?
Also specify the maximum values that can be assigned to each of the variables FROM and TO.
import random
FROM = random.randint(5, 15)
TO = random.randint(25, 45)
print(FROM, TO, sep="#")
Possible outputs:
(i) 5#25
(ii) 15#35
(iii) 12#40
(iv) 8#45

Q2. Observe the following program and answer the questions:


import random
VAL = ["A", "B", "C", "D"]
PICK = random.randint(1, 3)
print(VAL[PICK])
a) What is the minimum and maximum value that PICK can have?
b) Which of the following outputs is not possible?
(i) A
(ii) B
(iii) C
(iv) D

Q3. What possible output(s) are expected to be displayed when the following program is
executed?
import random
CODES = [101, 202, 303, 404]
X = random.randint(0, 1)
Y = random.randint(2, 3)
print(CODES[X], CODES[Y], sep="#")
Options:
(i) 101#303
(ii) 101#404
(iii) 202#303
(iv) 404#101

Q4. The following code is executed:


import random
FRUITS = ["APPLE", "MANGO", "GRAPE"]
N = random.randint(0, 2)
print(FRUITS[N] * 2)
What are the possible outputs?
(i) APPLEAPPLE
(ii) MANGOMANGO
(iii) GRAPEGRAPE
(iv) APPLEMANGO

Q5. What possible output(s) are expected to be displayed at the time of execution of the
following program?
Also, specify the maximum values that can be assigned to FROM and TO.
import random
FROM = random.randrange(20, 31, 10)
TO = random.randrange(30, 51, 10) print(FROM, TO, sep="#")
Options:
(i) 20#30
(ii) 20#50
(iii) 30#40
(iv) 10#50

Q7. What possible output(s) can be displayed by the following code?


import random
VAL = [100, 200, 300, 400]
P = int(random.random() * 4)
print(VAL[P])
Options:
(i) 100
(ii) 200
(iii) 300
(iv) 500

Q8.Observe the code and find all possible outputs:


import random
FRUITS = ["APPLE", "MANGO", "GRAPE", "PEAR"]
N = int(random.random() * 2) + 1
print(FRUITS[N])
Options:
(i) APPLE
(ii) MANGO
(iii) GRAPE
(iv) PEAR

You might also like