Random Function
Random Function
import random
AR = [20, 30, 40, 50, 60, 70]
FROM = random.randint(1, 3) NO-4. What possible output(s) are
TO = random.randint(2, 4) expected to be displayed on the screen at
the time of execution of the program?
for K in range(FROM, TO + 1):
print(AR[K], end="# ") P = 7
import random as r
val = 35
Page 1 of 3
Num = 0 import random
for i in range(1, 5): L = [10, 7, 21]
Num = val + r.randint(0, P - 1) X = random.randint(1, 2)
print(Num, " $ ", end="") for i in range(X):
P = P - 1 Y = random.randint(0, X - 1)
print(L[Y], "$", end=" ")
(a) 41 38 38 37
(b) 38 40 37 34 (i) 10 7
(c) 36 35 42 37 (ii) 21 7
(d) 40 37 39 35 (iii) 21 10
(iv) 7 $
(i) 1007510
NO-6. What possible outputs are (ii) 7510125
expected to be displayed on the screen at (𝑖𝑖𝑖)7510
the time of execution of the program?
(𝑖𝑣)10125$$100
Also, specify the maximum value that can be
assigned to each of the variables L and U.
import random NO-9. Study the following program and select the
Arr = [10, 30, 40, 50, 70, 90, 100] possible output(s) from the options (i) to (iv)
L = random.randrange(1, 3) following it. Also, write the maximum and the
U = random.randrange(3, 6) minimum values that can be assigned to the
for i in range(L, U + 1): variable Y.
print(Arr[i], "@", end="")
import random
(i) 40 @50 @ X = random.random()
(ii) 10 @50 @70 @90 @ Y = random.randint(0, 4)
(iii) 40 @50 @70 @90 @ print(int(X), ":", Y + int(X))
(iv) 40 @100 @
(i) 0 : 0
(ii) 1 : 6
(iii) 2 : 4
NO-7. What possible output(s) are (iv) 0 : 3
expected to be displayed on the screen at
the time of execution of the following
code? NO-10.
Study the following program and determine the
Also, specify the maximum and minimum value possible output(s) that may be displayed on the
that can be assigned to the variable X. screen when executed. Also, specify the minimum
Page 2 of 3
and maximum values that can be assigned to the can be assigned to the variable R when K is
variable NUMBER. assigned the value as 2.
import random import random
STRING = "CBSEONLINE" Signal = ['stop', 'Wait', 'Go']
NUMBER = random.randint(0, 3) for K in range(2, 0, -1):
N = 9 R = random.randrange(K)
while STRING[N] != "L": print(Signal[R], end='#')
print(STRING[N] + STRING[NUMBER] +
"#", end=" ")
NUMBER = NUMBER + 1
N = N - 1
(i) ES#NE#IO#
(ii) LE#NO#ON#
(iii) NS#IE#LO#
(iv) EC#NB#IS# NO-16.
What possible output(s) are expected to be
displayed on the screen at the time of execution of
NO-11. the program from the following code? Also,
Study the following program and determine the specify the minimum and maximum values that
possible output(s) that may be displayed on can be assigned to the variable End.
execution. import random
import random Colours = ["VIOLET", "INDIGO", "BLUE",
PICK = random.randint(0, 3) "GREEN", "YELLOW"]
CITY = ["DELHI", "MUMBAI", "CHENNAI", End = random.randrange(2) + 3
"KOLKATA"] Begin = random.randrange(End) + 1
for I in CITY: for i in range(Begin, End):
for j in range(1, PICK): print(Colours[i], end="&")
print(I, end=" ")
print()
(i)
DELHIDELHI MUMBAIMUMBAI
CHENNAICHENNAI KOLKATAKOLKATA
(ii)
DELHI
DELHIMUMBAI
DELHIMUMBAICHENNAI
(iii)
DELHI MUMBAI CHENNAI KOLKATA
(iv)
DELHI
MUMBAIMUMBAI
KOLKATAKOLKATAKOLKATA
NO-15.
What possible output(s) is/are expected to be
displayed on the screen at the time of execution of
the program from the following code? Also,
specify the maximum and minimum values that
Page 3 of 3