ASTER PUBLIC SCHOOL, GREATER NOIDA
WORKSHEET
SESSION: 2024-2025
CLASS/SEC: XI A & XI B
SUBJECT: COMPUTER SCIENCE TOPIC: PYTHON MODULES
SUBJECT TEACHER: MS. ASIMA CHAKRABARTY
Q1. What are the possible outcome(s) executed from the following code? Also specify the
maximum and minimum values that can be assigned to the variable NUM.
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 )
(i) BACKRIGHT (ii) BACKRIGHTFRONT
(iii) BACK (iv) LEFTFRONTRIGHT
Q2. 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
SIDES=["EAST","WEST","NORTH","SOUTH"]
N=random.randint(1,3) OUT=""
for I in range(N,1,–1):
OUT=OUT+SIDES[I] print
print(OUT)
(i) SOUTHNORTH (ii) SOUTHNORTHWEST
(iii) SOUTH (iv) EASTWESTNORTH
Q3. What are the possible outcome(s) executed from the following code? Also specify the maximum
and minimum values that can be assigned to variable PICK.
import random
PICK=random.randint(0,3)
CITY=["DELHI","MUMBAI","CHENNAI","KOLKATA"]
for I in CITY:
for J in range(1,PICK):
print(I, end=" ")
print()
Q4. What are the possible outcome(s) executed from the following code? Also specify the maximum
and minimum values that can be assigned to variable COUNT.
TEXT="CBSEONLINE"
COUNT=random.randint(0,3)
C=9
while TEXT[C]!='L':
print (TEXT[C]+TEXT[COUNT]+'*', end= “”)
COUNT=COUNT+1
C=C-1
i) EC*NB*IS* ii) NS*IE*LO* iii)ES*NE*IO* iv)LE*NO*ON*
Q5. What are the possible outcome(s) executed from the following code?
import random
print(int(20+random.random()*5),end=’ ‘)
print(int(20+random.random()*5),end=’ ‘)
print(int(20+random.random()*5),end=’ ‘)
print(int(20+random.random()*5))
Find out the suggested output option (i) to (iv). Also, write the least and highest value that can
be generated.
i) 20 22 24 25 ii) 22 23 24 25 iii) 23 24 23 24 iv) 21 21 21 21
Q6. What are the possible outcome(s) executed from the following code? Also specify the maximum
and minimum values that can be assigned to variables BEGIN and LAST.
import random
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#
Q7. What are the possible outcome(s) executed from the following code? Also specify the maximum
and minimum values that can be assigned to variables Guess used at the time of when value of
turn is 3.
import random
result=[”GOLD”, “SILVER”,”BRONZE”]
Getit=9
Guess=0
for turn in range (1,4):
Guess=random.randint(0,turn)
print((Getit,result[Guess],”*”,end=””)
i)9Gold*9Gold*8Silver*
ii)9Gold*7Bronze*8Gold*
iii)9Gold*8Silver*9Gold*
iv) IndexError:List index out of range
Q8 What are the possible outcome(s) executed from the following
code?
import random
alphs=[‘T’,”U”,”V”,”W”]
dig=[2,6,7,3]
print(“The Winner is:”,end=””)
print(alpha[random.randrange(0,3)],end=””)
for i in range(4):
print (dig[1+random.randint(0,2)],end=””)
i) The Winner is: T7363
ii)The Winner is: W7263
iii) The Winner is: T6323
iv) The Winner is: U3667
Q9 What are the possible outcome(s) executed from the following code? Also Specify the min and
max. Value of variable Count.
import random
Text=”DIGITALINDIA”
Count=random.randint(0,3)
c=9
while Text[c]!=’L’:
print(Text[c]+Text[Count]+’*’,end=””)
Count+=1
c-=1
i)DG*AL*IG ii)DD*NI*IG* iii)DI*NT*IA* iv)DI*NT*ID*
Q10 Go through the Python code shown below and find out the possible output from the suggested
output options i) to iv). Also write the minimum and Maximum values, which can be assigned to
the variable MyNum.
import random
MyNum=0
max=5
MyNum=15+random.randint(0,max)
for n in range(MyNum,20):
print(n,”$”,end=””)
i) 18$19$
ii)18$19$20$
iii)16$17$18$19$
iv)15$16$17$18$19$