Random Output Questions
Random Output Questions
com
import random
AR=[20,30,40,50,60,70]
FROM=random.randint(1,3)
TO=random.randint(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#
a. What is the minimum and maximum number of times the loop will execute?
b. Find out, which line 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
Answer:
a. Minimum Number = 1
Maximum number = 3
b. option (iv) is not expected to be a part of the output. Only (i), (ii) and (iii) are
possible output(s)
Q.3. What are the possible outcome(s) executed from the following code? Also,
specify the maximum and import random. [CBSE Delhi 2016]
PICK=random.randint (0,3)
CITY= ["DELHI", "MUMBAI", "CHENNAI", "KOLKATA"];
for I in CITY :
Unit-I: Programming and Computational Thinking-2 Visit: https://dineshkvs.wordpress.com
Q.4. What are the possible outcome(s) executed from the following code? Also,
specify the maximum and minimum values that can be assigned to variable SEL.
import random
SEL=random. randint (0, 3)
ANIMAL = [“DEER”, “Monkey”, “COW”, “Kangaroo”]
for A in ANIMAL:
for AA in range (1, SEL):
print (A, end =“ ”)
print ()
(i) (ii) (iii) (iv)
KANGAROOKANGAROO KANGAROO
Answer:
Maximum value of SEL is 3.
The possible output is below
Thus (i) and (iii) are the correct option.
Q5. What are the possible outcome(s) expected from the following python code?
Also specify maximum and minimum value, which we can have. [CBSE SQP 2015]
Unit-I: Programming and Computational Thinking-2 Visit: https://dineshkvs.wordpress.com
def main():
p = ‘MY PROGRAM’
i = 0
while p[i] != ‘R’:
l = random.randint(0,3) + 5
print(p[l],’-’)
i += 1
(i) R–P–O–R–
(ii) P–O–R–Y–
(iii) O -R – A – G –
(iv) A- G – R – M –
Answer:
Minimum value=5
Maximum value=8
So the only possible values are O, G, R, A
Only option (iii) is possible.
Q6. What possible output(s) are expected to be displayed on screen at the time
of execution of the following program: [CBSE AISSCE 2023]
first=(1,2,3,4)
sec=(1,2,3,4)
third=(1,2,3,4)
Therefore list item M will display either 10,15,20,25 only
(2 marks for the correct answer)
(Deduct ½ mark each for any other additional option along with correct option)
Q7. What possible output(s) are expected to be displayed on screen at the time of execution of the
following code ? 2
import random
S=["Pen","Pencil","Eraser","Bag","Book"]
for i in range (1,2):
f=random.randint(i,3)
Unit-I: Programming and Computational Thinking-2 Visit: https://dineshkvs.wordpress.com
s=random.randint(i+1, 4)
print(S[f], S[s], sep=":")
Options :
(I) Pencil:Book (II) Pencil:Book (III) Pen:Book (IV) Bag:Eraser
Eraser:Bag Bag:Book
Ans: Do it yourself