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

Random Assignment

Uploaded by

Dark Hacker
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Random Assignment

Uploaded by

Dark Hacker
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Q1.

Consider the code given below:


import random
r = random.randrange (100, 999, 5)
print(r, end = ' ')
r = random.randrange(100, 999, 5)
print(r, end = ' ')
r = random.randrange (100, 999, 5)
print(r)
Which of the following are the possible outcomes of the above
code? Also, what can be the maximum and minimum number
generated by line 2?
(a) 655, 705, 220 (b) 380, 382, 505 (c) 100, 500, 999 (d) 345,
650, 110

Q2. Consider the code given below:


import random
r = random.randint (10, 100) - 10
print(r, end = ' ')
r = random.randint (10, 100) - 10
print(r, end = ' ')
r = random.randint (10, 100) - 10
print(r)
Which of the following are the possible outcomes of the above
code? Also, what can be the maximum and minimum number
generated by line 2?
(a) 12 45 22 (b) 100 80 84 (c) 101 12 43 (d) 100 12 10

Q3. Consider the code given below:


import random
r= random.random() * 10
print(r, end = ' ')
r = random.random() * 10
print(r, end =' ')
r = random.random() * 10
print(r)
Which of the following are the possible outcomes of the above
code? Also, what can be the maximum and minimum number
generated by line 2?
(a) 0.5 1.6 9.8 (b) 10.0 1.0 0.0 (c) 0.0 5.6 8.7 (d)
0.0 7.9 10.0

Q4. Consider the code given below:


import statistics as st
v = [7, 8, 8, 11, 7, 7]
m1 = st.mean(v)
m2 = st.mode(v)
m3 = st.median(v)
print(m1, m2, m3)
Which of the following is the correct output of the above code?
(a) 7 8 7.5 (b) 8 7 7 (c) 8 7
7.5 (d) 8.5 7 7.5

Q5. 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 Lower and Upper
import random
AR = [20, 30, 40, 50, 60, 70]
Lower = random.randint(1,3)
Upper= random.randint(2,4)
for K in range (Lower, Upper+1):
print(AR[K], end=”#”)
Output Options:
(a) 10#40#70# (b) 30#40#50# (c)
50#60#70# (d) 40#50#70#
Q6. What possible output(s) are excepted to be displayed on the
screen after executing the following code?
import random
Lst=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
first= random.randrange(2,5)
second = random.randrange(1,3)
for L in range (second, first):
print(Lst[L], end = “@”)
Output Options:
(a) 1@2@3@ (2) 0@1@2@3@ (c)
2@3@ (d) 2@3@4@
Q7. What is possible output(s) is/are expected to be displayed on
screen after execution of the following program?
import random
Guess=65
for a in range(0,1):
for b in range (1,5):
New = Guess+random.randrange(0,b)
print(chr(New), end= ‘ ’)
(a) A B B C (b) A C B A (c)
B C D A (d) C A B D
Q8. What is possible output(s) is/are expected to be displayed on
screen after execution of the following program?
import random
MIN= 25
SCORE=5
for i in range(1,5):
Num=MIN+random.randrange(0,SCORE)
print(Num, end = “&”)
SCORE -=1
Output Options:
(a) 29&26&28&27& (b) 25&26&27&28& (c)
29&25&27&25& (d) 25&26&25&26&
Q9. What possible output(s) is/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 the
variables X and Y.
import random
X = random.randrange(0,3)+2
Y = random.randrange(1,3)+2
for i in range(X):
print("#", end= “”)
print("-", end=" ")
for i in range(Y):
print(“@”, end="")
Output Options:
(a) ##-@@@ (b) ###-@ (c) ######-
@@@ (d) ###-@@@@
Q10. What possible output(s) is/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 a
variable val, in each iteration.
import random
msg = "VIRTUAL"
index = len(msg)-1
while msg[index] != 'R':
val = random.randrange(2,index)
print(msg[val]+"#",end="")
index = index-1
(a) A#R#U#R# (b) A#R#T#T# (c)
U#A#R#R# (d) U#R#T#R#
Q11. What possible output(s) are expected to be display execution of
the following code?
import random
HIGH = 20
NUM = 15
for i in range(1,5):
N = HIGH+random.randint(11, NUM)
print(N, end = “:”)
NUM - = 1
Outputs:
(a) 35:31:34:32: (b)
35:34:33:32: (c)33:34:33:32: (d)
32:31:35:31:
Q12. What possible output(s) are expected to be displayed on one of
the execution of the following code is specify the maximum and
minimum values which can be assigned to the ‘Target’ by
randrange() function of random module.
import random
X= [11000, 999,99, 9]
Target = random.randrange(0,4)
for i in range(Target):
print(X[i], “#”)
(a) 1000# (b) 999# (c) 1000# (d) 999#
999# 99# 1000# 99#
99# 9# 999#

Q13. From the following Python code shown, below, find out the
possible output(s) from the suggested options.
import random
def week_days():
days=[“Mon”, “Tue”, “Wed”, “Thu”, “Fri”]
v = random.randrange(len(days)-1)
for i in range(v,0,-1):
print(days[i], “-“, i+1)
week_days()
(a) Thu- 4 (b) Wed-3 (c) Wed -3 (d) Fri-5
Wed-3 Tue-2 Tue-2 Thu-4
Tue-2 Mon-1

Q14. 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 both
the variables Beg and End.
import random
score= [11, 22, 33, 44, 55]
Beg = random.randrange(3)
End = random.randint(2,3)
for C in range(Beg, End):
print(Score[C],'#')
(a) 11# (b) 22# (c) 22# (d) 33#
22# 33# 33# 44#
33# 44#

Q13. 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 both
the variables Y.
import random
X = random.randrange(1,4)
Y= random.random()
print(“%2d”, %(Y+X), “@”, X)
(a) 00 @ 0 (b) 01 @ 1 (c) 02 @
2 (d) 04 @ 4

Q14. What possible output(s) are expected to be displayed on screen


at the time of execution of the program from the following code?
import random
n=4
while n>1:
val= random.randint(2,n)
for m in range(val)
if m%2= = 0:
print(m*2, end= “:”)
n=1
Output Option
(a) 0:4:0:0: (b) 0:0:0: (c) 0:4:0:4:0 (d) 0:4:0:4
Q15. 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 first and last values that can be assigned to a the
variables val in the last iteration.
import random
msg= “Luck”
x=1
for a in msg:
val=random.randint(0, len(msg)-x)
print(mag[val]+ “:”, end= “”)
x=x+1
(a) c:k:u:k: (b) k : u : c : c : (c) l : u :
u: c : (d) l : c : u : l :
Q15. What possible output(s) is/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
the variables ‘Assigned’.
import random
Ar= [10,7]
Assigned = random.randrange(10)+1
for C in range(0,2,1):
R=random.randint(1,2)-1
print(Ar[R]+Assigned, “@”, end= “ ”)
(a) 11@8@ (b) 20@21@ (c)
21@20@ (d) 8@11@
Q16. What possible output(s) is/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
the variables ‘high’.
import random
Ar=[11, 22, 33, 44, 55, 66 ]

low=random.randint(1,3)
high=random.randint(2,4)
for c in range(low, high+1):
print(Ar[c], end= “:”)
(a) 11 : 22 : 33 : (b) 22 : 33 : (c) 11 :
22: (d) 44 : 55 : 66 :
Q17. What possible output(s) is/are expected to be displayed on
screen at the time of execution of the program from the following
code?
from random import randint
Vibgyor=[[‘V’, ‘Violet’], [‘I’, ‘Indgo’], [‘B’, ‘Blue’], [‘G’,
‘Green’],[‘Y’, ‘Yellow’],[‘O’, ‘Orange’],[‘R’, ‘Red’]]
for i in range(3):
first=randint(0,1)
last=randint(1,2)+1
print(Vibgyor[last-first], end= ‘:’)
(a) [‘G’, ‘Green’]: [‘G’, ‘Green’]: [‘Y’, ‘Yellow’]:
(b) [‘G’, ‘Green’]: [‘B’, ‘Blue’]: [‘G’, ‘Green’]:
(c) [‘V’, ‘Violet’]: [‘B’, ‘Blue’]: [‘B’, ‘Blue’]:
(d) [‘I’, ‘Indgo’]: [‘B’, ‘Blue’]: [‘B’, ‘Blue’]:
Q18. 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.

import random

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

(a)ES#NE#IO# (b)LE#NO#ON# (c)NS#IE#LO# (d)EC#NB#IS#

Q19. Consider 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 the suggested output options (i) to (iv). Also, write the least
value 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


Q20. Consider the following code:

import random
print (100 + random.randint(5, 10), end = ' ')
print (100 + random.randint(5, 10), end = ' ')
print (100 + random.randint(5, 10), end = ' ')
print (100 + random.randint(5, 10))
Find the suggested output options (i) to (iv). Also, write the least
value and highest value that can be generated.

(i) 102 105 104 105 (ii) 110 103 104 105 (iii) 105 107
105 110 (iv) 110 105 105 110

Q21. What are the possible outcome(s) executed from the following
code ? Also specify the maximum and minimum values that can
be assigned to variable PICKER.
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()
(i) DELHIDELHI
MUMBAIMUMBAI
CHENNAICHENNAI
KOLKATAKOLKATA
(ii) DELHI
DELHIMUMBAI
DELHIMUMBAICHENNAI
(iii) DELHI
MUMBAI
CHENNAI
KOLKATA
(iv) DELHI
MUMBAIMUMBAI
KOLKATAKOLKATAKOLKATA

You might also like