Suggested Lab. Exercises · Q4
Q.ABC School has allotted unique token IDs from (1 to 600) to all the parents for facilitating a lucky draw on the day of their Annual day function. The winner would receive a special prize. Write a program using Python that helps to automate the task.(Hint: use random module)
CBSENCERTSubjective· 3mImportance★★★★★est
88% · 35/40 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →A fair lucky draw is exactly what pseudo-random number generation is for: random.randint(1, 600) returns each of the 600 token IDs with equal probability, both end-points included.
The idea — random number generation. Python's built-in random module produces pseudo-random numbers. For a lucky draw we need one integer in a closed range [1, 600], and random.randint(a, b) is the right tool because it includes both a and b — every parent's token has a chance.
import random
def luckyDraw():
"""Pick one winning token ID from 1 to 600 (both inclusive)."""
winner = random.randint(1, 600)
print("Lucky draw winner - Token ID:", winner)
luckyDraw()
Key lines
import random— brings in the random-number module.random.randint(1, 600)— returns a random integer N such that 1 <= N <= 600.- Wrapping the logic in the user-defined function
luckyDraw()means the school can re-run the draw (e.g. for a second prize) just by calling the function again. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.