What will be the output of the following Python function, assuming that the random module has already been imported? [code]random.uniform(3,4)[/code]

Ngô Thị Vân

New member
What will be the output of the following Python function, assuming that the random module has already been imported?
Code:
random.uniform(3,4)
A. Error
B. Either 3 or 4
C. Any integer other than 3 and 4
D. Any decimal value between 3 and 4
 
Answer: d
Explanation: This question depicts the basic difference between the functions random.randint(a, b) and random.uniform(a, b). While random.randint(a,b) generates an integer between ‘a’ and ‘b’, including ‘a’ and ‘b’, the function random.uniform(a,b) generates a decimal value between ‘a’ and ‘b’.
 

Tìm kiếm

Back
Top