Worksheet Python Modules
Worksheet Python Modules
1. Find the correct output(s) of the following code. Also write the maximum and
minimum values that can be assigned to variable Y.
import random
X=random.random()
Y=random.randint(0,4)
print (int(X),":",Y+int(X))
(A) 0:0
(B) 1:6
(C) 2:4
(D) 0:3
Ans. (A) and(D) are possible outputs. Maximum:0 Minimum:4
2.
3. Identify the correct output(s) of the following code. Also write the minimum
and the maximum possible values of the variable Lot
import random
word='Inspiration'
Lot=2*random.randint(2,4)
for i in range(Lot,len(word),3):
print(word[i],end='$')
i) i$a$i$n$ ii) i$n$ iii) i$t$n$ iv) a$i$n$
Ans. Minimum value possible for Lot: 4
Maximum value possible for Lot: 8
Possible outputs are : iii)
Page 1 of 5
4. 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#
Ans. (ii)30#40#50#
Maximum value assigned to FROM is 3
Maximum value assigned to TO is 4
5. Identify the correct output(s) of the following code. Also write the minimum
and the maximum possible values of the variable b.
import random
text = "Adventure"
b = random.randint(1, 5)
for i in range(0, b):
print(text[i], end='*')
6. What possible outputs are expected to be displayed on the screen at the time
of execution of the program from the following code?
import random
temp=[10,20,30,40,50,60]
c=random.randint(0,4)
for i in range(0, c):
print(temp[i],”#”)
a) 10#20# b) 10#20#30#40#50#
c) 10#20#30# d) 50#60#
Page 2 of 5
7. Find possible o/p (s) at the time of execution of the program from the
following code? Also specify the maximum values of variables Lower and
Upper.
import random as r
AR=[20, 30, 40, 50, 60, 70];
Lower =r.randint(1,3)
Upper =r.randint(2,4)
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. Identify the correct output(s) of the following code and write the minimum
and the maximum possible values of the variable b.
import random
a="ComputerScience"
I=0
while (I<3):
b=random.randint(1,len(a)-1)
print(a[b],end='$')
I+=2
A) C$m$ B) m$p$ C) c$n$ D)c$e$c$
Ans. B) m$p$ C) c$n$
Value of b minimum 1 and maximum 14
Page 3 of 5
9. 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-
Ans. (i)
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
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@
Ans. (a)
Page 4 of 5
11. 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&
Ans. (i)
12. 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) )
Page 5 of 5