Docsity

Python random functions class 12, Lecture notes of Computer science

Toggle sidebar
bg1
QUESTIONS OF RANDOM FUNCTIONS
1. 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#
2. Study the following program and select the possible output(s) from the options (i) to
(iv) following it. Also, write the maximum and the minimum values that can be
assigned to the variable Y.
import random
x = random.random( )
y = random . randint (0, 4 )
print ( int (x) , โ€œ : โ€ , y + int (x))
i) 0 : 0
ii) 1 : 6
iii) 2 : 4
iv) 0 : 3
pf2

Partial preview of the text

Download Python random functions class 12 and more Lecture notes Computer science in PDF only on Docsity!

QUESTIONS OF RANDOM FUNCTIONS

1. 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) 1 0#40#70# (ii) 30#40#50# (iii) 50#60#70# (iv) 40#50#70# 2. Study the following program and select the possible output(s) from the options (i) to (iv) following it. Also, write the maximum and the minimum values that can be assigned to the variable Y. import random x = random.random( ) y = random. randint (0, 4 ) print ( int (x) , โ€œ : โ€ , y + int (x)) i) 0 : 0 ii) 1 : 6 iii) 2 : 4 iv) 0 : 3

3. Observe the following program and answer the questions that follow: 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 option 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. Observe the following Python code and find out , which out of the given options i) to iv) are the expected correct output(s).Also assign the maximum and minimum value that can be assigned to the variable โ€˜Goโ€™. import random X =[100,75,10,125] Go = random.randint(0,3) for i in range(Go): print (X[i],"$$",end= โ€˜โ€™) i. 100$$75$$10 ii. 75$$10$$125$$ iii. 75$$10$$ iv. 10$$125$$