Answered step by step
Verified Expert Solution
Link Copied!

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 3020 Computational Thinking Assignment 1: 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 Assignment1. Then download the file
Assignment1.py and place it in the folder Assignment1. 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 six-sided die.
If you roll 1,2, or a 3, you lose that many dollars (up to the amount of money that you have).
For instance, if you roll 3 but have $2, you lose $2, but if you have $4 you lose $3.
If you roll 4,5, or a 6, you win that many dollars -3(up to the amount of money your opponent has).
For instance, if you roll 6 but your opponent has $2, you win $2, but if your opponent has $4 you win $3.
The game continues until one of the players runs out of money, and the winner is the one who ends up with non-zero 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 1 starts with m1 dollars and player 2 starts with m2 dollars, then:
Probability that player 1 wins a game =m1m1+m2
Probability that player 2 wins a game =m2m1+m2
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
Assignment1.py to implement your program. Prompt the user to input 3 numbers:
starting_amount1: The starting amount for Player 1(you).
starting_amount2: The starting amount for Player 2(your opponent)
reps: The number of replications to run the simulation (a number between 1000 and 10,000)
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 2 decimal places):
Average ending amount for Player 1: Sum of the ending amount for Player 1 over all replications divided by the number of replications.
Average ending amount for Player 2(like above).
Average highest amount that Player 1 achieves within each game: Record the highest amount that Player 1 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 2 achieves within each game (like above).
Probability that Player 1 wins a game (in percentages): Count the number of times that Player 1 wins a game, then divide by the number of replications.
Probability that Player 2 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 1: $100
Starting amount for Player 2: $50
Number of replications: 10000
Hint: You need to use nested loops. Do not use functions, lists, or anything not covered in Modules 1-4.
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 1:
Starting amount for Player 1:$10
Starting amount for Player 2: $20
Number of replications: 10000
Sample output 1:
Average ending amount for Player 1:$10.12
Average ending amount for Player 2: $19.88
Average highest amount that Player 1 achieves: $20.51
Average highest amount that Player 2 achieves: $27.82
Probability that Player 1 wins a game: 33.72%
Probability that Player 2 wins a game: 66.28%
Average number of rounds per game: 46.17
Sample input 2:
Starting amount for Player 1:$50
Starting amount for Player 2: $10
Number of replications: 10000
Sample output 2:
Average ending amount for Player
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Deductive And Object Oriented Databases Second International Conference Dood 91 Munich Germany December 18 1991 Proceedings Lncs 566

Authors: Claude Delobel ,Michael Kifer ,Yoshifumi Masunaga

1st Edition

3540550151, 978-3540550150

More Books

Students also viewed these Databases questions