0% found this document useful (0 votes)
40 views7 pages

Import Random

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)
40 views7 pages

Import Random

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/ 7

Random Module Outputs

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

(i) (ii) (iii) (iv)


DELHIDELHI DELHI DELHI DELHI
MUMBAIMUMBAI DELHIMUMBAI MUMBAI MUMBAIMUMBAI
CHENNAICHENNAI DELHIMUMBAICHENNAI CHENNAI KOLKATAKOLKATAKOLKATA
KOLKATAKOLKATA KOLKATA
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 ()

(i) (ii) (iii) (iv)


DEERDEER DEER DEER DEER
MONKEYMONKEY DELHIMONKEY MONKEY MONKEYMONKEY
COWCOW DELHIMONKEYCOW COW KANGAROOKANGAROOKANGAROO
KANGAROOKANGAROO KANGAROO
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

(i) (ii) (iii) (iv)


M_M_Y_P R_G_A_G G_G_R_O O_G_G_A

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)

(i) (ii) (iii) (iv)

0#1 0#1 0#1 0#1


1#2 1#2 1#2
2#3 2#3
3#4

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

(i) (ii) (iii) (iv)


BLUE BLUE PINK BLUEBLUE
PINK BLUEPINK PINKGREEN PINKPINK
GREEN BLUEPINKGREEN GREENRED GREENGREEN
RED BLUEPINKGREENRED GREENGREEN

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. Find best possible output


8. What possible output(s) are expected to be displayed on screen at the time of execution of
the following code ?

import random
S=["Pen","Pencil","Eraser","Bag","Book"]
for i in range (1,2):
f=random.randint(i,3)
s=random.randint(i+1, 4)
print(S[f], S[s], sep=":")
Options :
(I) Pencil: Book (II) Pencil: Book (III) Pen: Book (IV) Bag: Eraser
Eraser: Bag Bag: Book
9. Study the following program and select the possible output(s) from the options (i) to (iv)
following it. Also, write the maximum and the minimum values that can be assigned to the
variable Y.

import random
X= random.random()
Y= random.randint(0,4)
print(int(X),":",Y+int(X))
(i) 0: 0 (ii) 1: 6 (iii) 2: 4 (iv) 0: 3
10 What are the possible outcome(s) executed from the following code? Also specify the
maximum and minimum values that can be assigned to variable N.

import random
NAV = ["LEFT","FRONT","RIGHT","BACK"]
NUM = random.randint(1,3)
NAVG = ""
for C in range(NUM,1, -1):
NAVG = NAVG + NAV[C]
print(NAVG)

11. Observe the following Python code and find out which of the given options (i) to (iv) are the
expected correct output(s). Also, assign maximum and minimum values that can be assigned
to the variable ‘Go’.

import random
X= [100,75,10,125]
Go = random.randint (0,3)
for i in range(Go):
print(X[i],"$$",)
What will be the minimum and maximum value for ‘i’? Write all the possible output(s).

12. What possible output(s) is/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 start and end.

import random

POINTS= [30,50,20,40,45]

start=random. randint (1,3)

end=random. randint (2,4)

for c in range (start, end+1):

print(POINTS[c],"#",)

You might also like