0% found this document useful (0 votes)
189 views

Random Function

Random function practice for class 12

Uploaded by

ram priya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
189 views

Random Function

Random function practice for class 12

Uploaded by

ram priya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import random

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*

What will be the output of the following code?

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#

What possible outcome will be produced when the following code is


executed?
import random
value=random.randint(0,3)
fruit=["APPLE","ORANGE","MANGO","GRAPE"]
for i in range(value):
print(fruit[i],end='##')
print()
a) APPLE## b) APPLE# c) APPLE## ORANGE## d)
ORANGE##
MANGO##
APPLE##
ORANGE##
Choose the best option for the possible output of the following code
import random
L1=[random.randint(0,10) for x in range(3)]
print(L1)
(a) [0,0,7] (b) [9,1,7] (c) [10,10,10] (d) All are possible
OR
import random
num1=int(random.random()+0.5)
What will be the minimum and maximum possible values of variable num1

Sol:
All are possible
OR
Minimum 0 and maximum 1

What possible output(s) are expected to be displayed on screen at the time of


execution of the program from the following code?
import random
points=[30,50,20,40,45]
begin=random.randint(1,3)
last=random.randint(2,4)
for c in range(begin,last+1):
print(points[c],"#",end=’’)
(a) 20#50#30# (b) 20#40#45 (c) 50#20#40# (d) both (b) and (c)

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

You might also like