ASSIGNMENT 1 String Random
ASSIGNMENT 1 String Random
G B PUBLIC SCHOOL
DEPARTMENT OF COMPUTER SCIENCE
COMPUTER SCIENCE (083)-ASSIGNMENT 02
STRING AND RANDOM
1. 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]+'#',
NUMBER=NUMBER+1
N=N-1
(i) ES#NE#IO# (ii) LE#NO#ON# (iii) NS#IE#LO# (iv) EC#NB#IS#
2. 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 variables BEGIN and LAST.
import random
POINTS=[20,40,10,30,15] ;
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],"#",
(i) 20#50#30# (ii) 20#40#45# (iii) 50#20#40# (iv) 30#50#20#
3. 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
PLAY=[40,50,10,20]"EAST","WEST","NORTH","SOUTH";
ROUND=random.randint(2,3)
for J in range(ROUND,1,–1):
print PLAY[J],”:”
(i) 20:10: (ii) 20:10:50:
(iii) 20: (iv) 40:50:20:
4. 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.