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 NUMBER.


import random
STRING="CBSEONLINE"
NUMBER = random.randint (0, 3)
N=9
while STRING[N] != "L":
    print (STRING[N] + STRING[NUMBER] +  "#", end = " ")
    NUMBER = NUMBER +1
    N=N-1


(i) ES#NE#IO#
(ii)LE#NO#ON#
(iii)NS#IE#LO#
(iv)EC#NB#IS#

Answer =

Outcomes are (i)

Maximum value of NUMBER is 6.
Minimum value of NUMBER is 3.

Because Minimum value of NUMBER from random.randint (0, 3) is 0 and while loop will run only 3 times. So, Minimum value of NUMBER is 3.

Maximum value of NUMBER from random.randint (0, 3) is 3 and while loop will run only 3 times. So, Maximum value of NUMBER is 6.

 

Output of Code :-

EC# NB# IS# 3
>>>

EB# NS# IE# 4
>>> 

ES# NE# IO# 5
>>> 

EE# NO# IN# 6
>>> 

2 Comments

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

  1. why minimum value is not 0 and max 3

    ReplyDelete
    Replies
    1. Because Minimum value of NUMBER from random.randint (0, 3) is 0 and while loop will run only 3 times. So, Minimum value of NUMBER is 3.

      Maximum value of NUMBER from random.randint (0, 3) is 3 and while loop will run only 3 times. So, Maximum value of NUMBER is 6.

      Delete

Post a Comment

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

Previous Post Next Post