Assignment 4
Functions and Counting
Submit before 11:30 PM Friday October 6
Overview
You will write a program that simulates a turn in Monopoly to estimate the probability that the player ends in jail due to rolling doubles three times in a row.
Python Functions and Scripts
In the game of Monopoly, each turn consists of rolling a pair of dice and the player advances by the number of spaces indicated on the dice. If the player rolls doubles, the player goes again. However, if the player rolls doubles on a third roll, the player goes to jail. Follow the steps below to create a Python program to estimate the probability that a player goes to jail because of rolling triple doubles for any given turn.
- Study the dice_roll and doubleStats functions from lab 4. Create a function called doubles_roll that simulates a roll of a pair of dice. When rolling the pair of dice, it should invoke the die_roll function defined for lab 4. It should return True if doubles is rolled, False otherwise.
- Write a function called jail_result that simulates dice rolling for a turn in Monopoly. It should invoke your doubles_roll function and keep calling it if it returns True, up to three times. If it returns True 3 times, the jail_result function should return True. Otherwise, it should return False.
- Write a function called jail_stats. It should take one parameter that specifies the number of trials (size of the sample of Monopoly turns). It should run jail_result the number of times indicated by trials and count the True results. It should return the count of True results.
- Write Python code that calls jail_stats for a large number and shows the proportion (probability estimate) that a player will go to jail on a turn due to rolling 3 sets of doubles.
Consider sharing your estimate on Discord to check if it's the same as others.
Deliverables
Create a text file called assn4.txt that contains the following:
- A statement that summarizes your completion of the assignment. It should contain
the following information:
- Any help or resources that you used in completing the assignment.
- A summary of your experience possibly including your approach, difficulties and time you spent.
- For each of your Python programs or functions:
- A listing of the code
- Running examples that demonstrate that your code works correctly
Submit your assn4.txt file to D2L.