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
How is the highest value 24
ReplyDelete20+x*5
To get 24 , what must be given in x ..?
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.
Deletewhat is the correct output :
ReplyDeleteimport 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="#")
Output :-
Deletelower is: 1
upper is: 2
50#60#70#
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )