[go: up one dir, main page]

0% found this document useful (0 votes)
87 views5 pages

Random module WS 1

Uploaded by

harish.m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views5 pages

Random module WS 1

Uploaded by

harish.m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Class 12 RANDOM MODULE WORKSHEET

Introduction to Random Module

randint() – function takes starting and ending values both

randrange() - function takes only starting value and ending-1 value

random() - generates decimal values between 0 and 1 but not include 1

1.What are the possible outcome(s) from the following code?


import random
PICK=random.randint (1,3)
CITY= ["DELHI", "MUMBAI", "CHENNAI", "KOLKATA"]
for I in CITY:
for J in range (0, PICK):
print (I, end = "")
print ()

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 ()

3. What are the possible outcome(s) executed from the following


code ?
import random
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)

5. 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 ()
6. Which is the correct outcome executed from the following
code?
import random
n1= random.randrange(1, 10, 2)
n2= random.randrange(1, 10, 3)
print (n1,"and",n2)
1. 2 and 7
2. 3 and 4
3. 8 and 10
4. 8 and 9

7. What possible output(s) are expected to be displayed on screen at the


time of execution of the program from the following code? Also specify the
minimum values that can be assigned to each of the variables BEGIN and
LAST.

import random
VALUES = [10, 20, 30, 40, 50, 60, 70, 80]
BEGIN = random.randint (1, 3)
LAST = random.randint(2, 4)
for I in range (BEGIN, LAST+1):
print (VALUES[I], end = " - ")

(i) 30-40-50-
(ii) 10-20-30-40-
(iii) 30-40-50-60-
(iv) 30-40-50-60-70-

8. 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):
print (AR[K],end=”#“)

(i)10#40#70#
(ii)30#40#50#
(iii)50#60#70#
(iv)40#50#70#

9. Consider the following code:


import math
import random
print(str(int(math.pow(random.randint(2,4),2))))
print(str(int(math.pow(random.randint(2,4),2))))
print(str(int(math.pow(random.randint(2,4),2))))

What could be the possible outputs out of the given four choices?
i) 2 3 4
ii) 9 4 4
iii)16 16 16
iv)2 4 9

10. Consider the following code and find out the possible output(s) from
the options given below. Also write the least and highest value that can be
generated.

import random as r
print(10 + r.randint(10,15) ,end = ‘ ‘)
print(10 + r.randint(10,15) , end = ‘ ‘)
print(10 + r.randint(10,15) , end = ‘ ‘)
print(10 + r.randint(10,15))

i) 25 25 25 21
iii) 23 22 25 20
ii) 23 27 22 20
iv) 21 25 20 24

11. 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 BEG
and END.

import random
heights=[10,20,30,40,50]
beg=random.randint(0,2)
end=random.randint(2,4)
for x in range(beg,end):
print(heights[x],end=’@’)

(a)30 @
(b) 10@20@30@40@50@
(c) 20@30
(d) 40@30@

12. What possible outputs(s) are expected to be displayed on screen at


the time of
execution of the program from the following code. Select which option/s
is/are correct
import random
print(random.randint(15,25) , end=' ')
print((100) + random.randint(15,25) , end = ' ' )
print((100)-random.randint(15,25) , end = ' ' )
print((100) *random.randint(15,25))
(i) 15 122 84 2500
(ii) 21 120 76 1500
(iii) 105 107 105 1800
(iv) 110 105 105 1900
10. Consider the following code:
import random
r = random.randrange (100, 999, 5) #line 2
print(r, end = ' ')
r = random.randrange(100, 999, 5)
print(r, end = ' ')
r = random.randrange (100, 999, 5)
print(r)
Find the suggested output options (i) to (iv). What can be the maximum
and minimum number generated by line 2?
(a) 655, 705, 220 (b) 380, 382, 505 (c) 100, 500, 999 (d) 345,
650, 110

11. Consider the following code:

import random
STRING="CBSEONLINE"
NUMBER = random.randint (0, 3)
N=9
while STRING[N] != "L":
print (STRING[N] + STRING[NUMBER] + "#", end = " ")
NUMBER = NUMBER +1
N=N-1

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


time of execution of the program from the following code? Also, specify
the Minimum and Maximum values that can be assigned to the variable
Number.
(a) ES#NE#IO# (b)LE#NO#ON# (c) NS#IE#LO# (d) EC#NB#IS#

15. What possible output(s) is/are expected to be displayed on the screen


at the time of execution of the program from the following code?
Also, specify the maximum and minimum value that can be assigned to
the variable R when K is assigned value as 2. [CBSE Board 2021]
import random
Signal = [ 'Stop', 'Wait', 'Go' ]
for K in range(2, 0, -1):
R = randrange(K)
print (Signal[R], end = ' # ')

(a) Stop # Wait # Go #


(b) Wait # Stop #
(c) Go # Wait #
(d) Go # Stop #

You might also like