Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

These are all programs written in Python A popular game of chance frequently see

ID: 3666204 • Letter: T

Question

These are all programs written in Python

A popular game of chance frequently seen at casinos is a dice game known as “craps”. The game is played as follows. A player rolls two dice. Each die is the familiar six-sided die with faces containing 1, 2, 3, 4, 5, and 6 dots. After the dice are rolled, the next step is determined by the sum of the dots on the two top faces.

• If the sum is 7 or 11 on the first throw, the player wins.

• If the sum is 2, 3, or 12 on the first throw, the player loses (called “craps”).

• If the sum is 4, 5, 6, 8, 9, or 10 on the first throw, then that sum becomes the player’s “point”. Now, the only way for the player to win is by continuing to roll the dice until she “makes her point”. If the player rolls a 7 before making her point, she loses. In other words, if the roll of the dice adds up to her point, she wins; if it adds up to 7, she loses; if it adds up to neither, she rolls the dice again.

Note that there are two ways for a player to win: Either by rolling a 7 or 11 in the first roll of the dice, or by rolling her point in a subsequent roll of the dice.

You are asked to write a program to play craps to allow wagering. The player starts with an initial bank balance of $1000. Each game starts with a wager (which of course must be no bigger than the current bank balance). After one game, the bank balance is updated and the player is allowed to play again, repeatedly, until she quits, or the bank balance falls to $0. You will accomplish all this by implementing the following functions.

1, Write a function called roll dice with no parameters. The function rolls two dice and return the sum of the result. You can simulate the roll of a die by using the randint(a, b) function from the random module. randint(a, b) returns a random integer N such that a N b

2. The second function called play one game plays a single game of craps, using the rules described above. This function does not have parameters. It should print out sentences informing the player about the sequence of actions taking place in the game (see sample runs below - your code should mimic the output shown). It returns an integer value of 1 if the player wins the game, and in integer value of 0 if the player loses the game.

3. The third function called craps does not have any parameters. It uses a while loop to allow the player to play as many rounds of craps as she wants, as long as the bank balance is not $0. The function should first prompt the user to enter a wager.1 If the wager is greater than the bank balance, repeatedly prompt the player to re-enter the wager until a valid wager is entered. Then run one game of craps (using the play one game function), inform the player if she won or lost and update the bank balance accordingly. If the new balance is $0, print a message ("Sorry, you’re broke!"), and quit. As long as the balance is greater than $0, the player may repeatedly choose to play again. If the player quits with a bank balance greater than $0, print a congratulatory message if money was made and a sympathetic message if money was lost.

A sample run is shown below.

---------------------------- Welcome to the Craps program ----------------------------

Your initial bank balance is $1000.

What is your wager? 100

Okay, let’s play.

You rolled 11

You win!!

Your new bank balance is $1100

Do you want to play again? [y/n] y

What is your wager? 500

Okay, let’s play.

You rolled 12

Sorry, you lose!

Your new bank balance is $600

Do you want to play again? [y/n] y

What is your wager? 700

Cannot wager more than $600. Re-enter wager: 800

Cannot wager more than $600. Re-enter wager: 400

Okay, let’s play.

You rolled 4

Your point is 4

You rolled 5

You rolled 9

Explanation / Answer

from random import randrange
def main():
printIntro()
n = getInput()
x = crapsCasino(n)
printSummary(x,n)
def printIntro():
print('Program to simulate Craps Casino.')
print('Probability of winning the ber will show in result ')
def getInput():
n = eval(input('How many games to simulate: '))
return n
def crapsCasino(rounds):
win = 0
for i in range(rounds):
init = firstRoll()
if init == 'win': win = win+1
elif (type(init)) == int:
final = pointRoll(init)
if final == 'win': win = win+1
return win
def firstRoll():
x = dice()
if x == 7 or x == 11:
status = 'win'
elif x ==2 or x ==3 or x ==12:
status = 'lose'
else:
status = x
return status
def pointRoll(point):
x = 0
while not pointCheck(x,point):
x = dice()
if x == point:
status = 'win'
elif x == 7:
status = 'lose'
return status
def pointCheck(x,point):
return x == 7 or x == point
def dice():
return randrange(1,7)+randrange(1,7)
def printSummary(win,rounds):
print('==========')
print(' Games simulated:',rounds)
print('Total winning:',win)
print(' Probability of winning Craps is: {:0.2}'.format(win/rounds))
if __name__ == '__main__': main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote