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


(ii)

DELHI
DELHIMUMBAI
DELHIMUMBAICHENNAI


(iii)

DELHI
MUMBAI
CHENNAI
KOLKATA


(iv)

DELHI
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 

>>>

(ii)  If PEAK = 2 , Then "( for j in range(1, PICK):" will run 1 times ;

DELHI 
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".


9 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. would be helpful if the explanation was mentioned.

    ReplyDelete
  2. Please give us the detailed explanation. It would be really helpfull.

    ReplyDelete
  3. Thank you, it was really helpful :)

    ReplyDelete
  4. Option 1 is also correct. None of the options have a space between the words

    ReplyDelete
  5. 1st one is definitely incorrect
    Proof:
    End =" "
    Therefore they should have spaces bw them

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post