What will be the output of the following Python code? [code]random.seed(3) random.randint(1,5) 2 random.seed(3) random.randint(1,5)[/code]

What will be the output of the following Python code?
Code:
random.seed(3)
random.randint(1,5)
2
random.seed(3)
random.randint(1,5)
A. 3
B. 2
C. Any integer between 1 and 5, including 1 and 5
D. Any integer between 1 and 5, excluding 1 and 5
 
Answer: b
Explanation: We use the seed function when we want to use the same random number once again in our program. Hence the output of the code shown above will be 2, since 2 was generated previously following which we used the seed function.
 

Tìm kiếm

Back
Top