Test Index

Functions in Python Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 16 of 23
Marks: +1, -0
Which of the following output will never be obtained when the given code is executed ?
import random
Shuffle = random.randrange(10)+1
Draw = 10*random.randrange(5)
print ("Shuffle", Shuffle, end="#")
print ("Draw", Draw)
[CBSE 2024 Compartment]
Solution:  
Concept:
random.randrange(n) returns a random integer from 0 to n-1.
Explanation:
random.randrange(10) gives 0 to 9, so Shuffle = 0+1 to 9+1 = 1 to 10.
random.randrange(5) gives 0 to 4, so Draw = 10 × (0 to 4) = 0, 10, 20, 30 or 40.
Option A (1, 0), Option B (10, 10) and Option C (10, 0) are all possible.
Option D needs Shuffle = 11 and Draw = 50; neither value can ever occur.
Answer:
Option D (Shuffle 11 # Draw 50)
© examsnet.com
Advertisements
Go to Question: