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

2.1. Random Functions

Uploaded by

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

2.1. Random Functions

Uploaded by

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

RANDOM FUNCTIONS

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 maximum values that can be assigned to each
of the variable 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=“#”)
Study the following program and select the
possible output from (i) to (iv) following it. Also
write the maximum and minimum values
import random
X=random.random() OUTPUT
Y=random.randint(0,4)
Option (i) and
print (int(X),”:”,y+int(x)) (iv)

i) 0:0
ii) 1:6
iii) 2:4
iv) 0:3
Observe the following program and
answer the questions that follow
import random Output
X=3 a) 3 times
N=random.randint(1,X) b) Option 4
for i in range(N):
print(i, “#”, i+1)

a) What is the maximum and minimum number of times the loop will execute?
b) Find out which option of output(s) out of (i) to (iv) will not be expected from
the program ?
i) 0#1 ii)1#2 iii) 2#3 iv) 3#4
Observe the following Python code and find out
which option (i to iv) are the expected correct
output(s). Also assign the maximum value 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],‟$$‟,end=„ „)

100$$75$$10$$125
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.
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

i) ES#NE#IO# ii) LE#NO#ON# iii) NS#IE#LO# iv) EC#NB#IS#

You might also like