Answered step by step
Verified Expert Solution
Question
1 Approved Answer
BAIS 3 0 2 0 Computational Thinking Assignment 1 : Gambler's Ruin The purpose of this assignment is to use basic computer logic to implement
BAIS Computational Thinking Assignment : Gambler's Ruin
The purpose of this assignment is to use basic computer logic to implement a simple dice game. Use Spyder IDE to complete this assignment. Start by creating a folder on your local computer called Assignment Then download the file
Assignmentpy and place it in the folder Assignment In this file write a Python program that simulates a simple dice gambling game.
Problem description: The game is played between two players as follows:
You and your opponent start with some amount of money.
At each round, you roll a sixsided die.
If you roll or a you lose that many dollars up to the amount of money that you have
For instance, if you roll but have $ you lose $ but if you have $ you lose $
If you roll or a you win that many dollars up to the amount of money your opponent has
For instance, if you roll but your opponent has $ you win $ but if your opponent has $ you win $
The game continues until one of the players runs out of money, and the winner is the one who ends up with nonzero amount.
Fun fact: This dice game is known as Gambler's Ruin in probability theory. A fun fact about this game is that if player starts with dollars and player starts with dollars, then:
Probability that player wins a game
Probability that player wins a game
The purpose of this assignment is to verify this probability using simulation see the sample outputs and compare the probabilities with above In addition, we want to collect more interesting statistics such as how many rounds a game takes until a player goes broke.
Implementation: Use the provided template file
Assignmentpy to implement your program. Prompt the user to input numbers:
startingamount: The starting amount for Player you
startingamount: The starting amount for Player your opponent
reps: The number of replications to run the simulation a number between and
Use the randint function from Python's random module to get a die roll result. Set your code to run reps number of simulations of the game and collect and output the following statistics all rounded up to decimal places:
Average ending amount for Player : Sum of the ending amount for Player over all replications divided by the number of replications.
Average ending amount for Player like above
Average highest amount that Player achieves within each game: Record the highest amount that Player achieves within each game not necessarily the ending amount then sum these values over all replications and divide by the number of replications.
Average highest amount that Player achieves within each game like above
Probability that Player wins a game in percentages: Count the number of times that Player wins a game, then divide by the number of replications.
Probability that Player wins a game like above
Average number of rounds that each game takes averaged over all simulations
At the end of your code include the statistics as a comment for the following inputs:
Starting amount for Player : $
Starting amount for Player : $
Number of replications:
Hint: You need to use nested loops. Do not use functions, lists, or anything not covered in Modules
Sample inputs and outputs: Here are some sample inputs and the expected outputs. Note that due to randomness of the simulations, your outputs might be slightly different. But if you do everything correctly, your results should be very close to these values.
Sample input :
Starting amount for Player :$
Starting amount for Player : $
Number of replications:
Sample output :
Average ending amount for Player :$
Average ending amount for Player : $
Average highest amount that Player achieves: $
Average highest amount that Player achieves: $
Probability that Player wins a game:
Probability that Player wins a game:
Average number of rounds per game:
Sample input :
Starting amount for Player :$
Starting amount for Player : $
Number of replications:
Sample output :
Average ending amount for Player
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started