Random Function
Random Function
AR=[20,30,40,50,60,70]
START=random.randint(1,3)
END=random.randint(2,4)
for P in range(START, END+1):
print (AR[P],end=”#“)
Based on the above code what will Be the maximum value of the variables START and END ?
A. 3,4
B. 4,3
C. 2,4
D. 4,2
What possible outputs(s) will be obtained when the following code is
executed?
import random
VALUES = [10, 20, 30, 40, 50, 60, 70, 80]
BEGIN = random.randint(1,3)
LAST = random.randint(BEGIN, 4)
for x in range(BEGIN, LAST+1):
print(VALUES[x], end = "-")
a) 30-40-50- b) 10-20-30-40-
c) 30-40-50-60- d) 30-40-50-60-70-
What possible outputs(s) will be obtained when the following code is executed?
a. RAMAN** b.
SHIVAJI** SHIVAJI**
TAGORE** SHIVAJI**TAGORE**
c. d.
SHIVAJI** SHIVAJI** ASHOKA**
TAGORE** TAGORE** SHIVAJI*SHIVAJI*
TAGORE* TAGORE* TAGORE*
a. Delhi#Mumbai#Chennai#Kolkata# b. Mumbai#Chennai#Kolkata#Mumbai#
c. Mumbai# Mumbai #Mumbai # Delhi# d. Mumbai# Mumbai #Chennai # Mumbai
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+1):
print(AR[K],end=” #“ )
(i)10#40#70# (ii)30#40#50# (iii)50#60#70# (iv)40#50#70#
Sol:
All are possible
OR
Minimum 0 and maximum 1
What possible output(s) will be obtained when the following code is executed
import random
k=random.randint(1,3)
fruits=[‘mango’, ‘banana’, ‘grapes’, ‘water melon’, ‘papaya’]
for j in range(k):
print(j, end=“*”)
(a) mango*banana*grapes (b) banana*grapes
(c) banana*grapes*watermelon (d) mango*grapes*papaya
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#
sol:a or b or c