0% found this document useful (0 votes)
9 views10 pages

Python Random Output Exercises

The document contains a series of Python programming questions that involve the use of the random module to generate outputs based on various conditions and loops. Each question presents a code snippet and asks for possible outputs along with minimum and maximum values for certain variables. The questions cover a range of topics including lists, loops, and random number generation.

Uploaded by

hitesh.aimes
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)
9 views10 pages

Python Random Output Exercises

The document contains a series of Python programming questions that involve the use of the random module to generate outputs based on various conditions and loops. Each question presents a code snippet and asks for possible outputs along with minimum and maximum values for certain variables. The questions cover a range of topics including lists, loops, and random number generation.

Uploaded by

hitesh.aimes
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

P a g e | 201

Que1: import random


MAX=3
Number=50+[Link](0,MAX)
p=Number
while p>=50:
print( p , end="#")
p – =1

(i) 53#52#51#50#
(ii) 50#51#52#
(iii) 50#51#
(iv) 51#50#

Que2: import random


Score= [25,20,34,56, 72, 63]
Myscore = Score[[Link](2,3)]
print(Myscore)

(i) 25
(ii) 34
(iii) 20
(iv) None of the above

COMPUTER ACADEMY
9559961111
P a g e | 202

Que3: import random


Area= ["NORTH", "SOUTH", "EAST", "WEST"]
for i in range(3):
TOGO = [Link]( 1 , 2 )
print (Area[TOGO] , end= ":" )

(i) SOUTH : EAST : SOUTH :


(ii) NORTH : SOUTH : EAST :
(iii) SOUTH : EAST : WEST :
(iv) SOUTH : EAST : EAST :

Que4: import random


POINT =5
for I in range(4):
Number = [Link](15 , 15+POINT)
print( Number, end=':' )
POINT = POINT -1

(i) 19:16:15:18:
(ii) 14:18: 15:16:
(iii) 19:16:14:18:
(iv) 19:16:15:16:

COMPUTER ACADEMY
9559961111
P a g e | 203

Que5: import random


M=50
Guess=[Link](0, 3) + M
for c in range(Guess,56):
print(c, end='#')

(i) 50 # 51 # 52 # 53 # 54 # 55 #
(ii) 52 # 53 # 54 # 55 #
(iii) 53 # 54 #
(iv) 51 # 52 # 53 # 54 # 55

Que6: Observe the following program and find out, which output(s) out of (i) to (iv) will not be
expected from the program? What will be the minimum and the maximum value
assigned to the variable Chance
import random
Arr=[9,6]
Chance=[Link](0,1)+10
for C in range(2):
N=[Link](0,1)
print ( Arr[N]+Chance , end= "#" )
(i) 9# 6#
(ii) 19#17#
(iii) 19#16#
(iv) 20#16#

COMPUTER ACADEMY
9559961111
P a g e | 204

Que7: Based on the following Python code, find out the expected correct output(s) from the options (i)
to (iv). Also, find out the minimum and the maximum value that can be assigned to the
variable Guess used in the code at the time when value of Turn is

import random
Result= [ "GOLD", "SILVER", "BRONZE" ]
Getit=9
for Turn in range( 1 , 4 ):
Guess=[Link](0,Turn-1)
print( Getit – Guess , Result[Guess] , end= "*" )
(i) 9 GOLD*9 GOLD*8 SILVER*
(ii) 9 GOLD*7 BRONZE*8 GOLD*
(iii) 9 GOLD*8 SILVER*9 GOLD*
(iv) 9 GOLD*8 SILVER*8 GOLD*

COMPUTER ACADEMY
9559961111
P a g e | 205

Que8: Read the following Python code carefully and find out, which out of the given options (i) to (iv)
are the expected correct output(s) o fit. Also, write the maximum and minimum value that can
be assigned to the variable Taker used in the code:

import random
GuessMe = [100 , 50 , 200 , 20 ]
Taker= [Link](0,1) + 2
for Chance in range(Taker):
print ( GuessMe[Chance] , end="#" )

(i) 100# (iii) 100#50#200#


(ii) 50#200# (iv) 100#50

COMPUTER ACADEMY
9559961111
P a g e | 206

Que9: Study the following program and select the possible output(s) from the option (i) to (iv)
following it. Also, write the maximum and the minimum values that can be assigned to the
variable VAL.

import random
VAL=[Link](0,2)+2
guess="ABCDEFGHIJK"
for I in range( 1 , VAL +1):
for J in range( VAL , 8 ):
print ( GUESS[J] , end= “”)
print( )

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


BCDEFGH CDEFGH EFGH FGHI
BCDEFGH CDEFGH EFGH FGHI
EFGH FGHI
EFGH FGHI

COMPUTER ACADEMY
9559961111
P a g e | 207

Que10: Look at the following python code and find the possible output (s) from the options I to iv
following it. Also, write the maximum and minimum values that can be assigned to the
variable PICKER.

import random
PICKER = 1+ int ( [Link]( ) * 3 )
COLOR = [ “BLUE”, “PINK”, “GREEN”, “RED” ]
fort i in range(0 , PICKER+1):
for j in range( 0 ,i+1 ):
print ( COLOR[ j ] , end= “”)
print( )

i ii iii iv
PINK BLUE GREEN BLUE
PINKGREEN BLUEPINK GREENRED BLUEPINK
PINKGREENRED BLUEPINKGREEN BLUEPINKGREEN
BLUEPINKGREENRED

COMPUTER ACADEMY
9559961111
P a g e | 208

Que11: Look at the following Python code and find the possible output(s) from the options (i) to (iv)
following it. Also, write the maximum values that can be assigned to each of the variables N
and M.
import random
N=[Link](0,2)
M=[Link](0,3);
DOCK = [[1,2,3],[2,3,4],[3,4,5]]
for R in range (N):
for C in range(M):
print(DOCK[R][C],end="")
print( )

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


123 123 12 12
234 234 23 23
345 34

COMPUTER ACADEMY
9559961111
P a g e | 209

Que12: Look at the following Python code and find the possible output(s) from the options (i) to (iv)
following it. Also, write the highest and lowest values that can be assigned in the List A.
import random
A=list( )
for C in range(4):
[Link]([Link](0,C)+10)
for C in range(3,-1,-1):
print(A[C], end="@")

(i) 13@10@11@10@ (ii) 15$14$12$10$


(iii) 12@11@13@10 (iv) 12@11@10@10@

Que13. Observe the following python code and find the possible output(s) from the options (i)to (iv)
following it. Also, write the minimum and maximum values that can possibly be assigned to
the variable End .
import random
A=[10,20,30,40,50,60,70,80]
Start = [Link](0,1) + 1;
End = Start + [Link](0,3)
for I in range(Start, End+1):
print(A[I] , end="$" )

(i) 10$20$30$ (ii) 20$30$40$50$60$


(iii) 30$40$50$60$ (iv) 40$50$60$70$

COMPUTER ACADEMY
9559961111
P a g e | 210

Que14: What possible outputs(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 FROM and TO.

import random
AR=[20,30,40,50,60,70];
FROM=[Link](1,3)
TO=[Link](2,4)
for K in range(FROM,TO+1):
print (AR[K],end=”#“)

(i) 10#40#70#
(ii) 30#40#50#
(iii) 50#60#70#
(iv) 40#50#70#

Que15: What possible outputs(s) are expected to be displayed on screen at the time of execution of
the program from the following code? Also, write min. and max. value of Guess possible.
import random
H=4
Guess = [Link](1,H) + 30
for i in range(35, Guess,-1):
print(i , end="$" )
i) 35$34$33$ (ii) 35$34$33$32$31
(iii) 35$34$33$32$31$30 (iv) 35$34

COMPUTER ACADEMY
9559961111

You might also like