RANDOM MODULE
OUTPUT BASED QUESTIONS
1.What possible output(s) are expected to be
displayed on screen at the time of execution of
the program from the following code? Also
specify the minimum values that can be assigned
to each of the variables BEGIN and LAST.
import random
VALUES = [10, 20, 30, 40, 50, 60, 70, 80]
BEGIN = random.randint (1, 3)
LAST = random.randint(2, 4)
for I in range (BEGIN, LAST+1):
print (VALUES[I], end = "-")
(i) 30-40-50- (ii) 10-20-30-40- (iii) 30-40-50-60- (iv) 30-40-50-60-70-
------------------------------------------------------------------------------------------------------------------------
2. 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):
print (AR[K],end=”#“)
(i)10#40#70# (ii)30#40#50# (iii)50#60#70# (iv)40#50#70#
3.Consider the following code and find out the
possible output(s) from the options given below.
Also write the least and highest value that can be
generated.
import random as r
print(10 + r.randint(10,15) , end = ‘ ‘)
print(10 + r.randint(10,15) , end = ‘ ‘)
print(10 + r.randint(10,15) , end = ‘ ‘)
print(10 + r.randint(10,15))
i) 25 25 25 21 iii) 23 22 25 20 ii) 23 27 22 20 iv) 21 25 20 24
4.Consider the following code:
import math
importrandom
print(str(int(math.pow(random.randint(2,4),2))))
print(str(int(math.pow(random.randint(2,4),2))))
print(str(int(math.pow(random.randint(2,4),2))))
What could be the possible outputs out of the
given four choices?
i) 2 3 4 ii) 9 4 4 iii)16 16 16 iv)2 4 9
-------------------------------------------------------------------------------------------------------------------------
6. 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 BEG and END.
import random
heights=[10,20,30,40,50]
beg=random.randint(0,2)
end=random.randint(2,4)
for x in range(beg,end):
print(heights[x],end=’@’)
(a) 30 @ (b) 10@20@30@40@50@
(c) 20@30 (d) 40@30@
---------------------------------------------------------------------------------------------------------------------------
7. 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 Lower and Upper. import
random
AR=[20,30,40,50,60,70]
Lower =random.randint(1,4)
Upper =random.randint(2,5)
for K in range(Lower, Upper +1):
print (AR[K],end=”#“)
(i) 10#40#70# (ii) 30#40#50#
(iii) 50#60#70# (iv) 40#50#70#
------------------------------------------------------------------------------------------------------------------------------
8. What possible output(s) are expected to be
displayed on screen at the time of execution of
the program from the following code?
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# (iii) 50#60#70#
(ii) 30#40#50# (iv) 40#50#70#
----------------------------------------------------------------------------------------------------------------------------
9. What possible outputs(s) are expected to be
displayed on screen at the time of execution of
the program from the following code. Select
which option/s is/are correct
import random
print(random.randint(15,25) , end=' ')
print((100) + random.randint(15,25) , end = ' ' )
print((100) -random.randint(15,25) , end = ' ' )
print((100) *random.randint(15,25) )
(i) 15 122 84 2500 (ii) 21 120 76 1500
(iii) 105 107 105 1800 (iv) 110 105 105 1900
------------------------------------------------------------------------------------------------------------------------------
10. 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 minimum and maximum values that
can be assigned to the variable End .
import random
Colours = ["VIOLET","INDIGO","BLUE","GREEN",
"YELLOW","ORANGE","RED"]
End = randrange(2)+3
Begin = randrange(End)+1
for i in range(Begin,End):
print(Colours[i],end="&")
(i) INDIGO&BLUE&GREEN&
(ii) VIOLET&INDIGO&BLUE&
(iii) BLUE&GREEN&YELLOW&
(iv) GREEN&YELLOW&ORANGE&
--------------------------------------------------------------------------------------------------------------------------
11. What possible outputs(s) are expected to be
displayed on screen at the time of execution of
the program from the following code?
import random
X= random.random()
Y= random.randint(0,4)
print(int(),":",Y+int(X))
(i) 0:5 (ii) 0:3 (iii) 0:0 (iv) 2:5
-----------------------------------------------------------------------------------------------------------------------------
12. import random
x=random.random()
y=random.randint(0,4)
print(int(x),":",y+int(x))
Choose the possible output(s) from the given
options. Also write the least and highest value
that may be generated.
(i) 0:0 ii.) 1:6 iii.) 2:4 iv.) 0:3
-------------------------------------------------------------------------------------------------------------------------------
13. Observe the following Python code and find
out which of the given options (i) to (iv) are the
expected correct output(s). Also, assign
maximum and minimum values that can be
assigned to the variable ‘Go’.
import random
X=[100,75,10,125]
Go =random.randint(0,3)
for i in range(Go):
print(X[i],"$$")
(i) 100$$ (ii) 100$$75$$ 99$$10$$
(ii) 150$$ (iv) 125$$100$$ 10$$
------------------------------------------------------------------------------------------------------------------
14. import random
pick=random.randint(0,3)
city=["delhi","mumbai","chennai","kolkata"]
for i in city:
for j in range(1,pick):
print(i,end=" ")
-----------------------------------------------------------------------------------------------------------------
15. import random
p='my program'
i=0
while p[i]!='y':
t=random.randint(0,3)+5
print(p[t],'-')
i=i+1
-------------------------------------------------------------------------------------------------------------
16. import random
sel=random.randint(0,3)
animal=["deer","monkey","cow","kangaroo"]
for a in animal:
for aa in range(1,sel):
print(a, end="")
print()
------------------------------------------------------------------------------------------------------------
17. import random
picker=random.randint(0,3)
color=["blue","pink","green","red"]
for i in color:
for j in range(1,picker):
print(i, end="")
print()
-------------------------------------------------------------------------------------------------------------
18. 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 first, second and third.
from random import randint
LST=[5,10,15,20,25,30,35,40,45,50,60,70]
first = randint(3,8)
second = randint(4,9)
third = randint(6,11)
print(LST[first],"#", LST[second],"#", LST[third],"#")
(i) 20#25#25# (ii) 30#40#70#
(iii) 15#60#70# (iv) 35#40#60#
-------------------------------------------------------------------------------------------------------------------------