Page 1 :
RANDOM MODULE, randint() – function takes starting and ending values both, randrange()-function takes only starting value and ending-1 value, random()-generates decimal values between 0 and 1 but not include 1, 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 minimum values that can be assigned, to each of the variables BEGIN and LAST., import random, VALUES = [10, 20, 30, 40, 50, 60, 70, 80], BEGIN = random.randint (1, 3), LAST = random.randint(2, 4), for I in range (BEGIN, LAST+1):, print (VALUES[I], end = "-"), (i) 30-40-50(ii) 10-20-30-40(iii) 30-40-50-60- (iv) 30-40-50-60-70Ans, OUTPUT – (i) 30-40-50Minimum value of BEGIN: 1, Minimum value of LAST: 2, , 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):, print (AR[K],end=”#“), (i)10#40#70#, (ii)30#40#50#, (iii)50#60#70# (iv)40#50#70#, , Consider the following code: import math import, random, print(str(int(math.pow(random.randint(2,4),2)))), print(str(int(math.pow(random.randint(2,4),2)))), print(str(int(math.pow(random.randint(2,4),2)))), What could be the possible outputs out of the, given four choices?, i) 2 3 4, ii) 9 4 4, iii)16 16 16, iv)2 4 9, , Consider the following code and find out the, possible output(s) from the options given below., Also write the least and highest value that can be, generated. import random as r, print(10 + r.randint(10,15) , end = ‘ ‘), print(10 + r.randint(10,15) , end = ‘ ‘), print(10 + r.randint(10,15) , end = ‘ ‘), print(10 + r.randint(10,15)), 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), randint will generate an integer between 2 to 4, which is then raised to power 2, so possible, outcomes can be 4,9 or 16, 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 BEG and END., , Ans, Maximum value of FROM = 3, Maximum value of TO = 4, (ii) 30#40#50#, , Ans, Possible outputs :, i), iii) and iv), Least value : 10, Highest value : 15, 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 Lower and Upper. import, random
Page 2 :
import random, heights=[10,20,30,40,50], beg=random.randint(0,2), end=random.randint(2,4), for x in range(beg,end):, print(heights[x],end=’@’), (a) 30 @, (b) 10@20@30@40@50@, (c) 20@30, (d) 40@30@, , AR=[20,30,40,50,60,70], Lower =random.randint(1,4), Upper =random.randint(2,5), for K in range(Lower, Upper +1):, print (AR[K],end=”#“), , Ans, (a) & (b), Maximum value of BEG: 2, Maximum value of END: 4, 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, 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#, (iii) 50#60#70#, (ii) 30#40#50#, (iv) 40#50#70#, , Ans (i) ,(ii) and (iii), , Ans, (ii) 30#40#50#, 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 minimum and maximum values that, can be assigned to the variable End ., import random, Colours = ["VIOLET","INDIGO","BLUE","GREEN",, "YELLOW","ORANGE","RED"], End = randrange(2)+3, Begin = randrange(End)+1, for i in range(Begin,End):, print(Colours[i],end="&"), (i) INDIGO&BLUE&GREEN&, (ii) VIOLET&INDIGO&BLUE&, (iii) BLUE&GREEN&YELLOW&, (iv) GREEN&YELLOW&ORANGE&, Ans, (i) INDIGO&BLUE&GREEN&, , (i) 10#40#70#, (iii) 50#60#70#, , (ii) 30#40#50#, (iv) 40#50#70#, , What possible outputs(s) are expected to be, displayed on screen at the time of execution of, the program from the following code. Select, which option/s is/are correct, import random, print(random.randint(15,25) , end=' '), print((100) + random.randint(15,25) , end = ' ' ), print((100) -random.randint(15,25) , end = ' ' ), print((100) *random.randint(15,25) ), (i) 15 122 84 2500, (ii) 21 120 76 1500, (iii) 105 107 105 1800 (iv) 110 105 105 1900, Ans, (i) (ii) are correct answers., What possible outputs(s) are expected to be, displayed on screen at the time of execution of, the program from the following code?, import random, X= random.random(), Y= random.randint(0,4), print(int(),":",Y+int(X)), (i) 0:5, , (ii) 0:3, , (iii) 0:0, , (iv) 2:5, , Ans, (ii) and (iii)
Page 3 :
Minimum Value of End = 3, Maximum Value of End = 4, import random, x=random.random(), y=random.randint(0,4), print(int(x),":",y+int(x)), Choose the possible output(s) from the given, options. Also write the least and highest value, that may be generated., (i) 0:0, ii.) 1:6, iii.) 2:4, iv.) 0:3, Ans min value of x 0.01 and max value will be, 0.99899, Min value of y 0 and max value will be 4, Corrected options will be (i) and (iv), , (e) Observe the following Python code and find, out which of the given options (i) to (iv) are the, expected correct output(s). Also, assign, maximum and minimum values 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],"$$"), (i), , (ii), , 100$$, 75$$, 10$$, 150$$, 100$$, , (ii), , 100$$, 99$$, , (iv), , 125$$, 10$$, , Ans, (i), , 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=" "), , 100 $$, 75$$, 10$$, , import random, p='my program', i=0, while p[i]!='y':, t=random.randint(0,3)+5, print(p[t],'-'), i=i+1, , Ans, , delhi mumbai chennai Kolkata, , Ans, , delhi delhi mumbai mumbai chennai, chennai kolkata kolkata, , g –O- r- aorder can vary but print only these 4, characters, , 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(), , import random, picker=random.randint(0,3), color=["blue","pink","green","red"], for i in color:, for j in range(1,picker):, print(i, end=""), print(), , Ans, , Ans, , deer, , blue
Page 4 :
monkey, cow, kangaroo, , pink, green, red, , or, , or, , deer, deer, monkey, monkey, cow, cow, kangaroo, kangaroo, , blue, blue, pink, pink, green, green, red, 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., from random import randint, LST=[5,10,15,20,25,30,35,40,45,50,60,70], first = randint(3,8), second = randint(4,9), third = randint(6,11), print(LST[first],"#", LST[second],"#", LST[third],"#"), (i) 20#25#25#, (ii) 30#40#70#, (iii) 15#60#70#, Ans 35#40#60#, Maximum Values: First: 40, Second: 45, Third: 60, , (iv) 35#40#60#