Solved by verified expert:Needing assistance on explanation and how to come across this problem.As a reminder, the game is played as follows: roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which time the game is over and you keep whatever winnings you have accumulated.Write three functions for the dice game as well as a main function.The welcome function has no arguments and no return value. It simply prints a brief welcome to the player.The rollDie function has one argument, sides, with sides having a default value of 6. The function uses randint, and returns the value of the die roll.The playGame function has one argument, runs, which represents how many iterations of the simulation should be performed. The function has no return, but it has the bulk of the code needed to play the game, including the printing of results (average and largest winnings). This function should call the welcome function and the rollDie function (let the function use the default number of sides).Test by calling playGame from main, specifying 10000 runs.
test.docx
Unformatted Attachment Preview
import random
input(‘Press “enter” to roll the dice’)
n = 10000#Run 10,000 simulations of the game
dollar = 0
for i in range(n):
#—–single game start——-#
die = random.randint(1, 6) #randint function from Python’s random module to get a die roll
result
print (die)
if die == 1 or die == 2 or die == 3:
print(“Game Over”)
break
elif die == 4:
dollar += 4
elif die == 5:
dollar += 5
elif die == 6:
dollar += 6
#—–end of single game——#
# dollar #accumulated during the game
#i equals to the number of counts
if dollar < 0 or i < 0:
print('The average amount won is: ', 0) # since count start from 0 add one to get the actual
count
print('The largest amount won is: ', dollar) # since count start from 0 add one to get the actual
count
else:
avg = dollar / (i+1) # average amount won
print('The average amount won is: $', avg ) # since count start from 0 add one to get the
actual count
print('The largest amount won is: $', round(dollar,2)) # since count start from 0 add one to get
the actual count
...
Purchase answer to see full
attachment
You will get a plagiarism-free paper and you can get an originality report upon request.
All the personal information is confidential and we have 100% safe payment methods. We also guarantee good grades
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more