Random Assignment
Random Assignment
Q13. From the following Python code shown, below, find out the
possible output(s) from the suggested options.
import random
def week_days():
days=[“Mon”, “Tue”, “Wed”, “Thu”, “Fri”]
v = random.randrange(len(days)-1)
for i in range(v,0,-1):
print(days[i], “-“, i+1)
week_days()
(a) Thu- 4 (b) Wed-3 (c) Wed -3 (d) Fri-5
Wed-3 Tue-2 Tue-2 Thu-4
Tue-2 Mon-1
low=random.randint(1,3)
high=random.randint(2,4)
for c in range(low, high+1):
print(Ar[c], end= “:”)
(a) 11 : 22 : 33 : (b) 22 : 33 : (c) 11 :
22: (d) 44 : 55 : 66 :
Q17. What possible output(s) is/are expected to be displayed on
screen at the time of execution of the program from the following
code?
from random import randint
Vibgyor=[[‘V’, ‘Violet’], [‘I’, ‘Indgo’], [‘B’, ‘Blue’], [‘G’,
‘Green’],[‘Y’, ‘Yellow’],[‘O’, ‘Orange’],[‘R’, ‘Red’]]
for i in range(3):
first=randint(0,1)
last=randint(1,2)+1
print(Vibgyor[last-first], end= ‘:’)
(a) [‘G’, ‘Green’]: [‘G’, ‘Green’]: [‘Y’, ‘Yellow’]:
(b) [‘G’, ‘Green’]: [‘B’, ‘Blue’]: [‘G’, ‘Green’]:
(c) [‘V’, ‘Violet’]: [‘B’, ‘Blue’]: [‘B’, ‘Blue’]:
(d) [‘I’, ‘Indgo’]: [‘B’, ‘Blue’]: [‘B’, ‘Blue’]:
Q18. What are the possible outcome(s) executed from the following
code? Also specify the maximum and minimum values that can be
assigned to variable NUMBER.
import random
STRING="CBSEONLINE"
N=9
NUMBER = NUMBER +1
N=N-1
import random
print (int( 20 + random.random()*5), end =" ")
print (int( 20+ random.random()*5), end =" ")
print (int(20 + random.random()*5), end = " ")
print (int( 20 + random.random()*5))
Find the suggested output options (i) to (iv). Also, write the least
value and highest value that can be generated.
import random
print (100 + random.randint(5, 10), end = ' ')
print (100 + random.randint(5, 10), end = ' ')
print (100 + random.randint(5, 10), end = ' ')
print (100 + random.randint(5, 10))
Find the suggested output options (i) to (iv). Also, write the least
value and highest value that can be generated.
(i) 102 105 104 105 (ii) 110 103 104 105 (iii) 105 107
105 110 (iv) 110 105 105 110
Q21. 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
PICK = random.randint (0, 3)
CITY = ["DELHI", "MUMBAI", "CHENNAI", "KOLKATA"]
for I in CITY :
for j in range(1, PICK):
print(I, end =" ")
print()
(i) DELHIDELHI
MUMBAIMUMBAI
CHENNAICHENNAI
KOLKATAKOLKATA
(ii) DELHI
DELHIMUMBAI
DELHIMUMBAICHENNAI
(iii) DELHI
MUMBAI
CHENNAI
KOLKATA
(iv) DELHI
MUMBAIMUMBAI
KOLKATAKOLKATAKOLKATA