Lottery Tickets Generator Project

Lottery Tickets Generator

Python Programming Practice

 

Write a Python 3 script to generate 10 unique lottery tickets, each containing 10 numbers from 0 to 99. The objective of this Python programming practice is to ensure that all numbers from 0 to 99 are covered within the ten tickets, without any duplicates.

Algorithm Explanation:
1. Start by initializing an empty list to store the lottery tickets.
2. Create a loop that runs 10 times to generate 10 tickets.
3. Within each iteration of the loop, create an empty set to store the numbers for the current ticket.
4. Generate random numbers from 0 to 99 until the set contains 10 unique numbers.
5. Add the set of numbers to the list of tickets.
6. Repeat steps 3-5 until all 10 tickets are generated.
7. Finally, print the list of tickets.

Expected Output

Lottery Ticket 1: [52, 13, 62, 91, 80, 27, 78, 53, 7, 71]

Lottery Ticket 2: [89, 30, 67, 18, 35, 41, 93, 3, 40, 88]

Lottery Ticket 3: [32, 45, 64, 92, 11, 68, 23, 54, 58, 49]

Lottery Ticket 4: [83, 0, 46, 42, 1, 59, 20, 48, 39, 38]

Lottery Ticket 5: [37, 84, 85, 51, 33, 6, 87, 5, 65, 2]

Lottery Ticket 6: [50, 57, 95, 63, 24, 31, 90, 8, 72, 29]

Lottery Ticket 7: [74, 70, 98, 86, 28, 76, 81, 75, 19, 26]

Lottery Ticket 8: [36, 10, 94, 79, 82, 25, 96, 61, 9, 14]

Lottery Ticket 9: [22, 15, 66, 47, 77, 43, 16, 12, 34, 60]

Lottery Ticket 10: [99, 56, 69, 17, 21, 4, 73, 55, 44, 97]

Guide

Steps to complete this Python project:

  1. Import Necessary Modules:
    • Import the random module to shuffle the list of numbers.
  2. Generate Lottery Tickets:
    • Create a list containing all numbers from 0 to 99.
    • Shuffle the list to randomize the order of the numbers.
    • Divide the shuffled list into 10 equal parts, each part representing a unique lottery ticket.
  3. Display the Lottery Tickets:
    • Print each of the 10 lottery tickets with their respective numbers.

Benefits

This Python programming practice will not only help you reinforce your understanding of fundamental Python concepts such as lists, loops, list comprehension and the random module but also develop your problem-solving skills and algorithmic thinking.

Solutions

Here’s the complete source code for this Python programming practice:

import random

# Generate lottery tickets
all_numbers = list(range(100))
random.shuffle(all_numbers)
lottery_tickets = [all_numbers[i*10:(i+1)*10] for i in range(10)]

# Display the lottery tickets
for i, ticket in enumerate(lottery_tickets):
    print(f"Lottery Ticket {i+1}: {ticket}")

More advanced Python projects here!

We will be happy to hear your thoughts

Leave a reply

Python and Excel Projects for Practice
Register New Account
Shopping cart