Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (3 votes)
2K views

Random Output Questions

Uploaded by

gaytreesingh6148
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
2K views

Random Output Questions

Uploaded by

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

Unit-I: Programming and Computational Thinking-2 Visit: https://dineshkvs.wordpress.

com

Random function output Questions (2Marks)


Q1. 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=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#

Ans: (ii) 30#40#50#


Maximum value of
FROM=3
TO = 4
Q.2 Observe the following program and answer the question that follows:
import random
x=3
N = random, randint (1, x)
for i in range (N):
print (i, ‘#’, i + 1)

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

for J in range (1, PICK)


print (I, end = " ")
print ()
(i) (ii)
DELHIDELHI DELHI
MUMBAIMUMBAI DELHIMUMBAI
CHENNAICHENNAI DELHIMUMBAICEHNNAI
KOLKATAKOLKATA
(iii) (iv)
DELHI DELHI
MUMBAI MUMBAIMUMBAI
CHENNAI KOLKATAKOLKATAKOLKATA
KOLKATA
Answer:
Option (i) and (iii) are possible option (i) only
PICKE maxval = 3 minval = 0

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)

DEERDEER DEER DEER DEER

MONKEYMONKEY DELHIMONKEY MONKEY MONKEYMONKEY

COWCOW DELHIMONKEYCOW COW KANGAROOKANGAROOKANGA

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]

Ans: (i) 10#25#15


20#25#25

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

You might also like