# Sample Questions on randint() function in Python

Go through the Python code snippets given below, and find out the possible output(s) from the suggested options. Also write the least value and the highest value generated by the programs.

``````import random as r
Num = r.randint(0, 3)
N = len(Str) - 1
while Str[N] != 'L':
print(Str[N] + Str[Num] + "#", end = "")
Num = Num - 1
N = N - 1``````

(a) GM#GE#DH#AP#
(b) PS#GM#DE#AH#
(c) P@#GM#D@#AH#

``````import random as r
City = ["DEL", "CHN", "KOL", "BOM", "BNG"]
Fly = 0
for i in range(0, 3):
Fly = r.randint(0, 1) + 1
print(City[Fly], ":", end = "")``````

(a) DEL:CHN:KOL:
(b) CHN:KOL:CHN:
(c) KOL:BOM:BNG:
(d) KOL:CHN:KOL:

``````import random as r
Arr = [5, 8, 2]
Chance = r.randint(1, 2) + 12
for c in range(0, 3):
N = r.randint(0, 2)
print(Arr[N] + Chance, "@", end = "")``````

(a) 15 @18 @15 @
(b) 19 @19 @24 @
(c) 22 @16 @19 @
(d) 16 @22 @15 @

``````import random as r
val = 35
P = 7
Num = 0
for i in range(1, 5):
Num = val + r.randint(0, P - 1)
print(Num, " \$ ", end = "")
P = P - 1``````

(a) 41 \$ 38 \$ 38 \$ 37 \$
(b) 38 \$ 40 \$ 37 \$ 34 \$
(c) 36 \$ 35 \$ 42 \$ 37 \$
(d) 40 \$ 37 \$ 39 \$ 35 \$

``````import random as r
t =("Book", 7, "5G", "HSMS")
for i in range(0, 4):
x =r.randint(0, 2) + 1
print(t[x], "@", end = "")``````

(a) Book @5G @7 @HSMS @
(b) HSMS @Book @Book@5G @
(c) HSMS @5G @5G @7 @
(d) 7 @HSMS @HSMS @Book @

This site uses Akismet to reduce spam. Learn how your comment data is processed.