Practice short problems on Python Random Module
Practice short problems on Python Random Module
Module
PYTHON MODULES
2.What are the possible outcome(s) from the following code? Also, specify the maximum and
minimum values that can be assigned to variable SEL.
import random
SEL=random. randint (1, 3)
ANIMAL = ["DEER", "Monkey", "COW", "Kangaroo"]
for A in ANIMAL:
for AA in range (0, SEL):
print (A, end ="")
print ()
KANGAROOKANGAROO KANGAROO
Ans. Maximum value of SEL is 3 and minimum is 1
(iv) is the correct option.
3.What are the possible outcome(s) executed from the following code ?
import random
def main():
p = "MY PROGRAM"
i = 0
while p[i] != "R":
l = random.randint(0,3) + 5
print (p[l],end ="_")
i += 1
main()
4.Which is the incorrect outcome executed from the following code? Also, specify the maximum
and minimum values that can be assigned to variable
x = 3
N = random.randint (1, x)
for i in range (N):
print (i, "#", i + 1)
movie1 = random.choice(movie_list)
movie2 = random.choice(movie_list)
print ( movie1 ," or " ,movie2)
1. Finding Nemo or Harry Potter
2. Harry Potter or Toy Story
3. Frozen or The Jungle Book
4. Toy Story or Spider Man
Ans. (ii) and (iv) are incorrect option.
6.What are the possible outcome(s) executed from the following code ?
import random
color_list = ["Pink", "Red", "Sky blue", "Yellow", "Green"]
random.shuffle(color_list)
print ( color_list )
1. 57 and i
2. 62 and S
3. 20 and p
4. 30 and M
Ans. (iii) and (iv) are incorrect options
8.What are the possible outcome(s) executed from the following code ? Also specify the maximum
and minimum values that can be assigned to variable PICKER.
import random
N=3
PICKER = random.randint (1, N)
COLOR = ["BLUE", "PINK", "GREEN", "RED"]
for I in COLOR :
for J in range (0, PICKER):
print (I, end = " ")
print ()
9.What are the possible outcome(s) for “Jumble String”, when following code will be executed?
import random
stringN = "SimplyCoding"
char_list = list(stringN)
random.shuffle(char_list)
stringN = ''.join(char_list)
print ( stringN )
1. ( CmodlnpgiSyi )
2. miSiypgoCdln
3. ‘lCSgpimiondy’
4. kpCyodigntS
Ans. (ii) will be printed
1. 2 and 7
2. 3 and 4
3. 8 and 10
4. 8 and 9
Ans. (ii) is correct