CSCI 161: You never know.
This is a continuation of our in-class code simulating a lottery.
We now have code that can simulate a single lottery. You need to expand this code into not one, not ten, but any number of simulations of the lottery. Imagine someone who buys a lottery ticket every week. In less than 20 years, this person will have purchased more than 1,000 lottery tickets. You need to simulate how much money this person would have won or lost over the years. As a refresher, here are the rules for the simple version of the Texas lottery:
Pick 6 numbers between 1-54:
- If all 6 match, you win the jackpot. This can vary wildly between $5,000,000 and $36,000,000. We’ll just take an optimistic value of $20,000,000.
- If 5 of the 6 match, you get $2,000.
- If 4 of 6 match, you get $50.
- If 3 of 6 match, you get $3.
- Otherwise, you get nothing.
So you will ask the user how many rounds are to be simulated, and then print the numbers the user picked (can be fixed or random, doesn’t really matter), the numbers that actually came up, and keep a running total of the amount spent (easy: $1 per round) and the amount won (see bullet list above). At the end of the simulation, print the total profit (unlikely) or loss after playing.
This assignment is also worth 30 points.
Not much to say. User input is important, as is showing the results. It should be able to handle any number of rounds. You should not allow duplicate choices.
You’ll want to make some methods. One for the computer to pick numbers, one for the user to pick numbers, and one to compare the numbers. We already have the code to do this, but not in methods.
You don’t need to keep track of every round! You only need to keep track of the running total.
An interesting extra credit option might be to keep playing until you make a profit. This would in addition to the assignment, and would work differently, since you don’t know how many rounds there will be. It also might run forever, since the nature of a lottery isn’t to profit the player…