Q. What are the possible outcome(s) executed from the following code ? Also specify the maximum and minimum values that can be assigned to variable PICKER.
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 =" ")
print()
(i)
DELHIDELHI
MUMBAIMUMBAI
CHENNAICHENNAI
KOLKATAKOLKATA
MUMBAIMUMBAI
CHENNAICHENNAI
KOLKATAKOLKATA
(ii)
DELHI
DELHIMUMBAI
DELHIMUMBAICHENNAI
DELHIMUMBAI
DELHIMUMBAICHENNAI
(iii)
DELHI
MUMBAI
CHENNAI
KOLKATA
MUMBAI
CHENNAI
KOLKATA
(iv)
DELHI
MUMBAIMUMBAI
KOLKATAKOLKATAKOLKATA
MUMBAIMUMBAI
KOLKATAKOLKATAKOLKATA
Answer = (iii) , Minimum value of PEAK = 0 , Maximum value of PEAK = 3 .
Explanation:-
Only 4 types of output will give by program :-
(i) If PEAK = 3 , Then "( for j in range(1, PICK):" will run 2 times ;
DELHI DELHI
MUMBAI MUMBAI
CHENNAI CHENNAI
KOLKATA KOLKATA
>>>
MUMBAI MUMBAI
CHENNAI CHENNAI
KOLKATA KOLKATA
>>>
(ii) If PEAK = 2 , Then "( for j in range(1, PICK):" will run 1 times ;
DELHI
MUMBAI
CHENNAI
KOLKATA
>>>
MUMBAI
CHENNAI
KOLKATA
>>>
(iii) If PEAK = 1 , Then "( for j in range(1, PICK):" will run 0 times ;
>>>
There will only space due to statement print()
(iv) If PEAK = 1 , Then "( for j in range(1, PICK):" will run 0 times ;
>>>
There will only space due to statement print()
So, Suitable option is (iii)
(i) option is incorrect because there is no space between "DELHIDELHI".
would be helpful if the explanation was mentioned.
ReplyDeleteOk, Please read again : )
DeletePlease give us the detailed explanation. It would be really helpfull.
ReplyDeleteOk, Please read again : )
DeleteThank you, it was really helpful :)
ReplyDeleteWelcome : )
DeleteOption 1 is also correct. None of the options have a space between the words
ReplyDelete1st one is definitely incorrect
ReplyDeleteProof:
End =" "
Therefore they should have spaces bw them
Right.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )