The output of the following Python code is either 1 or 2. [code]import random random.randint(1,2)[/code]

The output of the following Python code is either 1 or 2.
Code:
import random
random.randint(1,2)
A. True
B. False
 
Answer: a
Explanation: The function random.randint(a,b) helps us to generate an integer between ‘a’ and ‘b’, including ‘a’ and ‘b’. In this case, since there are no integers between 1 and 2, the output will necessarily be either 1 or 2’.
 

Tìm kiếm

Back
Top