Q. Consider the following code:


import random

print (int( 20 + random.random()*5), end =" ")
print (int( 20+ random.random()*5), end =" ")
print (int(20 + random.random()*5), end = " ")
print (int( 20 + random.random()*5))

Find the suggested output options (i) to (iv). Also, write the least value and highest value that can be generated.


(i) 20 22 24 25
(ii) 22 23 24 25
(iii) 23 24 23 24
(iv) 21 21 21 21

Answer =

Option (iii) & (iv) will generate only.

Highest value is 24
Least value is 20

4 Comments

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

  1. How is the highest value 24
    20+x*5
    To get 24 , what must be given in x ..?

    ReplyDelete
    Replies
    1. Because x is in between 0 to 1. So, 0.999.. is highest value of x so, if convert to integer then it give highest value 4.

      Delete
  2. what is the correct output :
    import random
    AR=[20,30,40,50,60,70]
    lower=random.randint(1,3)
    print("lower is: ",lower)
    upper=random.randint(2,4)
    print("upper is: ",upper)
    for i in range(3,6):
    print(AR[i],end="#")

    ReplyDelete
    Replies
    1. Output :-

      lower is: 1
      upper is: 2
      50#60#70#
      >>>

      Delete

Post a Comment

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

Previous Post Next Post