Skip to content

Commit c80c0a9

Browse files
Create 05 Pick6
1 parent 71e7546 commit c80c0a9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

1 Python/labs/05 Pick6

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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. Order matters, if the winning numbers are [5, 10] and your ticket numbers are [10, 5] you have 0 matches. 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).
8+
9+
a ticket costs $2
10+
if 1 number matches, you win $4
11+
if 2 numbers match, you win $7
12+
if 3 numbers match, you win $100
13+
if 4 numbers match, you win $50,000
14+
if 5 numbers match, you win $1,000,000
15+
if 6 numbers match, you win $25,000,000
16+
17+
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. Another function could be num_matches(winning, ticket) which returns the number of matches between the winning numbers and the ticket.
18+
Steps
19+
20+
Generate a list of 6 random numbers representing the winning tickets
21+
Start your balance at 0
22+
Loop 100,000 times, for each loop:
23+
Generate a list of 6 random numbers representing the ticket
24+
Subtract 2 from your balance (you bought a ticket)
25+
Find how many numbers match
26+
Add to your balance the winnings from your matches
27+
After the loop, print the final balance
28+
29+
Version 2
30+
31+
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

Comments
 (0)