NCERT Computer Science Class #11 – Chapter #7 Solutions – Q #11

Chapter #7 – Functions

NCERT Computer Science Class #11 – Chapter #7 Solutions – Lab Exercises #4

Chapter #7 – Lab Exercises #4

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).

Python Program:

import random

def lucky_draw():
    # Define the range of token IDs
    token_ids = list(range(1, 601))
    
    # Randomly select one token ID
    winner_token_id = random.choice(token_ids)
    
    # Display the winner
    print(f"The winner of the lucky draw is token ID: {winner_token_id}")

# Run the lucky draw
if __name__ == "__main__":
    lucky_draw()

You can checkout the code from Github here – Lab Exercises #4

Explanation:

1.	Importing the Random Module: The program starts by importing the random 
        module, which provides functions to generate random numbers.
2.	Defining Token IDs: A list of token IDs from 1 to 600 is created using 
        range().
3.	Selecting a Winner: The random.choice() function is used to select one ID 
        randomly from the list of token IDs.
4.	Displaying the Winner: Finally, it prints out the selected token ID as the 
        winner.

NCERT Computer Science Class 11 Chapter 7 Solutions Q 11

Posts created 29

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top