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)
Question
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)
✨ Free AI Tools for You
Powered by Chatterbot AI
Answer
Here's a Python program that uses the random
module to select a random winner from the token IDs ranging from 1 to 600:
import random
def select_winner():
# Define the range of token IDs
token_ids = range(1, 601)
# Select a random token ID
winner = random.choice(token_ids)
# Announce the winner
print(f"The lucky draw winner is token ID: {winner}")
# Call the function to select and announce the winner
select_winner()
In this program:
The range
1 to 600
is created usingrange(1, 601)
.The
random.choice()
function is used to select a random token ID from this range.The selected winner is then printed as the output.
India's 1st AI Doubt Solver for CBSE, JEE, and NEET
Ask a Question for Freeand then it's just ₹212 a month