|
| 1 | +Lab 5: Pick6 |
| 2 | + |
| 3 | +Have the computer play pick6 many times and determine net balance. |
| 4 | + |
| 5 | +Initially the program will pick 6 random numbers as the 'winner'. Then try playing pick6 100,000 times, with the ticket cost and payoff below. |
| 6 | + |
| 7 | +A ticket contains 6 numbers, 1 to 99, and the number of matches between the ticket and the winning numbers determines the payoff. |
| 8 | +Order matters, if the winning numbers are [5, 10] and your ticket numbers are [10, 5] you have 0 matches. |
| 9 | +If the winning numbers are [5, 10, 2] and your ticket numbers are [10, 5, 2], you have 1 match. Calculate your net winnings (the sum of all expenses and earnings). |
| 10 | + |
| 11 | + a ticket costs $2 |
| 12 | + if 1 number matches, you win $4 |
| 13 | + if 2 numbers match, you win $7 |
| 14 | + if 3 numbers match, you win $100 |
| 15 | + if 4 numbers match, you win $50,000 |
| 16 | + if 5 numbers match, you win $1,000,000 |
| 17 | + if 6 numbers match, you win $25,000,000 |
| 18 | + |
| 19 | +One function you might write is pick6() which will generate a list of 6 random numbers, which can then be used for both the winning numbers and tickets. |
| 20 | +Another function could be num_matches(winning, ticket) which returns the number of matches between the winning numbers and the ticket. |
| 21 | +Steps |
| 22 | + |
| 23 | + Generate a list of 6 random numbers representing the winning tickets |
| 24 | + Start your balance at 0 |
| 25 | + Loop 100,000 times, for each loop: |
| 26 | + Generate a list of 6 random numbers representing the ticket |
| 27 | + Subtract 2 from your balance (you bought a ticket) |
| 28 | + Find how many numbers match |
| 29 | + Add to your balance the winnings from your matches |
| 30 | + After the loop, print the final balance |
| 31 | + |
| 32 | +Version 2 |
| 33 | + |
| 34 | +The ROI (return on investment) is defined as (earnings - expenses)/expenses. Calculate your ROI, print it out along with your earnings and expenses. |
0 commit comments