…
…
Study a campus festival club stand's dice game and raffle with probability and simulation; answer from the data whether the game makes the stand a profit and whether "Saturday tickets are lucky".
At the campus festival, a student club opens a stand to raise donations. The stand has two parts. The first is a dice game: the player buys a $1 ticket and rolls two dice; a total of 7 wins $3, and double six wins $15. The second is a raffle: 350 tickets were sold over two days, and 35 prizes were drawn by lottery at closing. The club president asks two questions: "Does the dice game make a profit for the stand, and could we close a day at a loss?" and "Everyone says Saturday tickets are lucky; is that true?" First you will find the probability by counting, then check it with a simulation, and finally test a claim by simulation.
Data: There is no data for the dice game; you will generate the rolls. For the raffle there is raffle_tickets.csv (fictional sample data), where each row is one ticket sold (350 rows):
| Column | Description |
|---|---|
ticket_no | Ticket number (B001–B350) |
day | Day the ticket was sold: Friday or Saturday |
buyer | Who bought the ticket: student or guest (not used in this project) |
result | Lottery result: prize or blank |
Lessons used: line chart and a title that states the result (17); probability and simulation, law of large numbers (23); conditional probability and crosstab (24); testing a claim by simulation and the p-value (27, 28); permutation test (29).
Cells share one session; each step uses the variables of the previous one. Simulations are seeded with np.random.default_rng(42), so when you run a cell again you see the same numbers.
What you'll do
Required topics
raffle_tickets.csvDownload file
Reading file…
Code cells are for members
You can read the steps. Sign up free to run the code, complete the steps and save your progress.
The club's game is played with two dice: the player buys a $1 ticket and rolls two dice. If the total is 7 they win $3, if they roll double six (total 12) they win $15; in every other case the ticket stays with the stand. To price the prizes correctly, you first need the probability of the two outcomes.
Two fair dice have 6 × 6 = 36 equally likely pairs (first die 1–6, second die 1–6). Walk through these 36 pairs with two nested loops, count the ones that total 7 and the double six, then compute the share of each as p_seven and p_double_six (lesson 23: probability is the share of an event among equally likely cases).
Which is more likely: the two dice totaling 7, or totaling 12?
This step's code cell is for members.Sign up free
Counting says something; the club president still asks, "does it really come out like that?" Instead of running the stand 10,000 times, let the computer make 10,000 rolls (lesson 23: seeded generator, rng.integers(1, 7, size=(rows, columns)); the upper bound 7 is not included).
Let each row be one roll and each column one die. Add along the row and store the total of each roll as
Code cells are for members
You can read the steps. Sign up free to run the code, complete the steps and save your progress.
totalThis step's code cell is for members.Sign up free
Someone at the club objects: "Last night 10 people played and only one rolled a 7. 1/6 is a myth." Answer this objection with a single chart: as the number of rolls grows, how does the share of 7s so far change? (Lesson 23: law of large numbers, cumsum() and np.arange; lesson 17: line chart and a title that states the result.)
Use the total array from the previous step. In the chart you draw the simulation line yourself; the theoretical 1/6 line is ready.
This step's code cell is for members.Sign up free
The real question: does the club make money with this game? In one game the stand takes $1 and pays $0, $3 or $15 depending on the result. Over many games, the average payout per game is each prize multiplied by its own probability and added up; this is called the expected payout (in lesson 23 the expected number of returns for 20 packages was 20 × 0.072; here the "weight" of each outcome is its probability). Subtract it from the ticket price and you get the expected profit per game.
Then do the same calculation with the simulation: find what the stand paid in each of the 10,000 rolls from step 2 and take the mean of the profit. Because True counts as 1 and False as 0, (total == 7) * 3 gives 3 on a roll with a 7 and 0 on the others.
This step's code cell is for members.Sign up free
A profit of about $0.08 per game looks good, but the club's cash box lives one day at a time. About 150 games are played on a festival day. Simulate 5,000 festival days: 150 rolls each day, with that day's total profit added to a list. Then find what share of the days ended at a loss (the "repeat thousands of times with a loop, add to a list, look at the distribution" pattern from lessons 27–30).
Then choose your answer to the club president and write its letter as verdict:
This step's code cell is for members.Sign up free
The second job of the stand is a raffle. On the two days of the festival (Friday, Saturday) 350 tickets were sold, and 35 prizes were drawn by lottery at closing. Now a post is going around on social media: "Two thirds of the winners bought a Saturday ticket, Saturday tickets are lucky!"
Separate two different questions (lesson 24: conditional probability and crosstab):
Compute both and put them next to the share of tickets sold on Saturday. Which question is the "two thirds" in the post?
This step's code cell is for members.Sign up free
The prize rate of Saturday tickets (12.0%) is about 5 points higher than Friday's (7.3%). If the lottery is truly fair, how often would a difference this large come up by chance? The permutation test from lesson 29 asks exactly this: if the day does not matter, shuffling the day labels at random changes nothing. Compute the difference between Saturday and Friday over 10,000 shuffles, and measure how ordinary the observed difference is in this distribution with a two-sided p-value (lesson 28).
Then pick what this result does and does not allow, and write its letter as verdict:
This step's code cell is for members.Sign up free