Random Function
Random Function
Consider the following code: import math import Consider the following code and find out the
random possible output(s) from the options given below.
print(str(int(math.pow(random.randint(2,4),2)))) Also write the least and highest value that can be
print(str(int(math.pow(random.randint(2,4),2)))) generated. import random as r
print(str(int(math.pow(random.randint(2,4),2)))) print(10 + r.randint(10,15) , end = ‘ ‘)
What could be the possible outputs out of the print(10 + r.randint(10,15) , end = ‘ ‘)
given four choices? print(10 + r.randint(10,15) , end = ‘ ‘)
i) 2 3 4 ii) 9 4 4 print(10 + r.randint(10,15))
iii)16 16 16 iv)2 4 9 i) 25 25 25 21 iii) 23 22 25 20
ii) 23 27 22 20 iv) 21 25 20 24
Ans
Possible outputs : ii) , iii) Ans
randint will generate an integer between 2 to 4 Possible outputs :
which is then raised to power 2, so possible i), iii) and iv)
outcomes can be 4,9 or 16 Least value : 10
Highest value : 15
What possible outputs(s) are expected to be What possible outputs(s) are expected to be
displayed on screen at the time of execution of displayed on screen at the time of execution of
the program from the following code? Also the program from the following code? Also
specify the maximum values that can be assigned specify the maximum values that can be assigned
to each of the variables BEG and END. to each of the variables Lower and Upper. import
random
import random AR=[20,30,40,50,60,70]
heights=[10,20,30,40,50] Lower =random.randint(1,4)
beg=random.randint(0,2) Upper =random.randint(2,5)
end=random.randint(2,4) for K in range(Lower, Upper +1):
for x in range(beg,end): print (AR[K],end=”#“)
print(heights[x],end=’@’)
(a) 30 @ (b) 10@20@30@40@50@ (i) 10#40#70# (ii) 30#40#50#
(c) 20@30 (d) 40@30@ (iii) 50#60#70# (iv) 40#50#70#
(i) INDIGO&BLUE&GREEN&
(ii) VIOLET&INDIGO&BLUE& Ans
(iii) BLUE&GREEN&YELLOW& (ii) and (iii)
(iv) GREEN&YELLOW&ORANGE&
Ans
(i) INDIGO&BLUE&GREEN&
Minimum Value of End = 3
Maximum Value of End = 4
import random (e) Observe the following Python code and find
x=random.random() out which of the given options (i) to (iv) are the
y=random.randint(0,4) expected correct output(s). Also, assign
print(int(x),":",y+int(x)) maximum and minimum values that can be
Choose the possible output(s) from the given assigned to the variable ‘Go’.
options. Also write the least and highest value
that may be generated. import random
(i) 0:0 ii.) 1:6 X=[100,75,10,125]
iii.) 2:4 iv.) 0:3 Go =random.randint(0,3)
Ans min value of x 0.01 and max value will be for i in range(Go):
0.99899 print(X[i],"$$")
Min value of y 0 and max value will be 4
Corrected options will be (i) and (iv) (i) 100$$ (ii) 100$$
75$$ 99$$
10$$
(ii) 150$$ (iv) 125$$
100$$ 10$$
Ans
(i) 100 $$
75$$
10$$
Ans Ans
deer blue
monkey pink
cow green
kangaroo red
or or
deer blue
deer blue
monkey pink
monkey pink
cow green
cow green
kangaroo red
kangaroo red
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 first, second and third.
Ans 35#40#60#
Maximum Values: First: 40, Second: 45, Third: 60