Lottery Number Generator

Our lottery number generator will produce the specified number of random numbers using a cryptographically strong random number algorithm. Most lotteries require the selection of 5, 6, or 7 numbers, usually out of the numbers from 1 to 35, 1 to 47, 1 to 49. However, many different lotteries exist. SoftLotto is a free lottery software for Windows.It basically works as a random number generator through which you can generate random lottery numbers. With this software, you can also generate repeated lottery numbers to increase the chances of players to win. Look up past drawing results, view hot/cold numbers, and generate lucky numbers. Through lottery number wheeling you can play more numbers than you normally would be able to play as I explained above. If you really get how powerful this strategy is then you will have found out how to win the lottery with science. There is no real algorithm to predict lottery numbers but that doesn’t mean there is no way to beat the lottery.

Lottery Number Generator Machine

In this challenge we are going to write a Python program that automatically generates six random numbers (from 1 to 50) and display them on the screen, sorted in ascending order.

The program will need to make sure that each number is unique; the same number cannot come twice in the selection of six selected numbers.

Script

Learning Objectives


By completing this code, you will understand the difference between the two types of loops used in Python:
  • For Loops (Count-Controlled Loops): A count-controlled loop is one that is executed a certain number of times. In our example, because we know that we need exactly six numbers we are going to use a for loop to repeat (iterate through) some of our code exactly six times.
  • While Loops (Condition-Controlled Loops): A condition-controlled loop such as a While loop keeps going while a certain condition is true. As soon as the condition becomes false, the loop stops iterating. In our case, when generating a random number, we are going the check that the new number has not already been picked up. If it has then we are going to generate a new one and will carry on doing so till we get a number that has not already been picked up.

Check the code

Your Challenge

  1. Complete this code to store your own selection of six numbers. For testing purposes, you can store these numbers directly into the code and display these to the end-user. Alternatively you can ask the end-user to type six numbers.
  2. Then your code will use the program given above to generate the six lottery numbers.
  3. Finally your code will check and inform the end-user of how many numbers the user guessed correctly by comparing the user’s six numbers with the six randomly generated lottery numbers!

Note


The probability of guessing several lottery numbers is very low. You may want to tweak your program to only pick up numbers between 1 and 20 (instead of 50). This will give you a better chance to guess some of these numbers and hence test whether your code is working.

Video Tutorial



Other challenges you may enjoy...

Best Lottery Number Generator

Tagged with: iteration, List, Python Challenge

Comments are closed.