2.1. Random Functions
2.1. Random Functions
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