RANDOM MODULE QUESTIONS
Q1. After the execution of the following Python script, what will be the correct output(s) from the options
given below? What will be the minimum value and the maximum value stored in the variable pos?
import random
string='COMPUTER'
for k in range(4):
pos=random.randint(3,6)
print(string[pos],end='')
i) PUTU ii) CMCP iii) ETTU iv) URER
Q2. Study the following program and select the possible output(s) from the options (i) to (iv) following it.
Also, write the maximum and the minimum values that can be assigned to the variable Y.
import random
X=random.random()
Y=random.randint(0,4)
print(int(X),":",Y+int(X))
i) 0:0 ii) 1 : 6 iii) 2: 4 iv)0 : 3
Q3. (i) What are the possible outcome(s) executed from the following code?
Also specify the maximum and minimum values that can be assigned to variable NUM.
NAV=[“LEFT”,”FRONT”,”RIGHT”,”BACK”]
NUM=random.randint(1,3)
NAVG=””
for C in range(NUM,1,-1):
NAVG=NAVG+NAV[C]
print(NAVG)
i. BACKRIGHT ii. BACKRIGHTFRONT iii. BACK iv. LEFTFRONTRIGHT
(ii) Which module is required for the above code?
Q4. What possible outputs(s) are expected to be displayed on screen at the time of execution of the program
from the following code? Also specify the maximum values that can be assigned to each of the variables
FROM and TO.
import random
AR=[20,30,40,50,60,70]
FROM=random.randint(1,3)
TO=random.randint(2,4)
for K in range(FROM,TO+1):
print (AR[K],end=”#“)
(i) 10#40#70# (ii) 30#40#50# (iii) 50#60#70# (iv) 40#50#70
IDENTIFY THE MODULE AND OUTPUT QUESTIONS
Q5. Identify and write the name of the module to which the following functions belong:
1. ceil( )
2. mode()
3. randrange()
Q6. Give output of the following:
(a) print(math.ceil(240.7))
(b) print(math.floor(-12.3))
(c) print(math.pow(3,4))
(d) print(statistics.mean([1,2,3,4,5])