|
| 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. |
| 35 | +# ==================================================================================================================================================== |
| 36 | + |
| 37 | +import random |
| 38 | + |
| 39 | +def pick6(): |
| 40 | + numlist = [] |
| 41 | + for r in range(6): |
| 42 | + x = random.randint(1,99) |
| 43 | + numlist.append(x) |
| 44 | + print(numlist) |
| 45 | + |
| 46 | +pick6() |
| 47 | +pick6() |
| 48 | +#============================== |
| 49 | + |
| 50 | +# simulations = 100,000 |
| 51 | +# possible_values = list(range(0,6)) |
| 52 | +# # print(possible_values) |
| 53 | + |
| 54 | +# outcomes = {i: 0 for i in possible_values} |
| 55 | + |
| 56 | +# for i in range(simulations): |
| 57 | +# d1 = random.randint(0,99) |
| 58 | +# d2 = random.randint(0,99) |
| 59 | + |
| 60 | +# outcome = d1 + d2 |
| 61 | +# outcomes[outcome] += 1 |
| 62 | + |
| 63 | +# print(outcomes) |
| 64 | + |
| 65 | +#================================= |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
0 commit comments