Python Programs

Random Lottery Number Generator In Python

Published July 3, 2023 by Jarvis Silva

In this article we will create a python program to generate lottery number, this program will generate a random lottery number so we will use the python random module to generate random numbers.

import random

num_numbers = int(input("How many lottery numbers would you like to generate? "))
max_number = int(input("What is the maximum number for the lottery? "))

lottery_numbers = random.sample(range(1, max_number + 1), num_numbers)

print("Your lottery numbers are:")
for number in lottery_numbers:

Above is the python code to generate lottery numbers, In the code I have first imported the random module then we take 2 inputs from the user, first input is how many lottery numbers to generate and next input is what should be the maximun number in a lottery.

Next we use the random.sample() method, it takes a range of numbers from 1 to the maximum number specified by the user and generates a random number between that range then finally we print the generated lottery numbers, below is an example output.

How many lottery numbers would you like to generate? 5
What is the maximum number for the lottery? 1000
Your lottery numbers are:

As you can see we successfully created the lottery number generator using python, you can run this program on your computer or use this online python compiler.

Here are some more related python tutorials you will find useful:

I hope you found what were you looking for from this article, if you want updates of our latest articles then join our telegram channel.

Thanks for reading, have a nice day 🙂