Question

In: Computer Science

Write a program in Python to simulate a Craps game: 1. When you bet on the...

Write a program in Python to simulate a Craps game:

1. When you bet on the Pass Line, you win (double your money) if the FIRST roll (a pair of dice) is a 7 or 11, you lose if it is ”craps” (2, 3, or 12). Otherwise, if it is x ∈ {4, 5, 6, 8, 9, 10}, then your point x is established, and you win when that number is rolled again before ’7’ comes up. The game is over and you will lose when ’7’ comes up before your established point.

Please can you do a step by step explanation and how it works?

Solutions

Expert Solution

from random import *

#get usr input function
def get_Input():
    #Enter the amount of games of craps need to be simulate
    number=int(raw_input())
    return number

#printing the result function
def print_Results(number, win_count):
    #printing the result of the simulation
    print('\nFor', number, 'games of craps simulated,', win_count, 'games were wins, giving success rate of '+ str(100*(win_count/number)) + '%.')



#roll function which return the win count
def sim_Roll(n):
    #declare roll count initialise to 0
    rollCount=0
    #declare wincount initialise to 0
    winCount=0
    #declare pointforroll initialise to 0
    PointForRoll=0
    #using while loop till n given input by user
    while rollCount < n:
        #increment the rollcount
        rollCount=rollCount+1
        #get the random roll of two roll and add , save it to randomroll variable
        randomRoll=randrange(1,7) + randrange (1,7)
        #given condition in the question if roll is 2,3,or 12 then player loss
        #so wincount will not incement
        if randomRoll == 2 or randomRoll == 3 or randomRoll == 12:
            winCount = winCount + 0
        #given condition in the question if roll is 7,or 11 then player loss
        #so wincount will  incement by 1
        if randomRoll == 7 or randomRoll == 11:
            winCount = winCount + 1
        #else while loop using pointfor roll according to the given condition
        else:
            while PointForRoll != 7 or PointForRoll != randomRoll:
                PointForRoll = randrange(1,7) + randrange(1,7)
                #if pointfor roll is equal to random roll 
                #then wincout will be wincount number
                if PointForRoll == randomRoll:
                    winCount=winCount
                #if pointfor toll is equal to 7 then wincount incement by 1
                if PointForRoll == 7:
                    winCount=winCount+1
                #returning pintforroll
                return PointForRoll
    #returning the wincount
    return winCount


#craps function for the simulation
def craps():
    #Taking user input
    number=get_Input()
    #calling the Roll function to get the win count
    win_count=sim_Roll(number)
    #printing the result 
    print_Results(number, win_count)

#calling the craps simulator function
craps()

Related Solutions

For this assignment, write a program that uses functions to simulate a game of Craps. Craps...
For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7 or 11, the player...
Overview For this assignment, write a program that uses functions to simulate a game of Craps....
Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7 or 11, the...
In the game of Craps, you roll two dice. When you bet on a “snake eyes”,...
In the game of Craps, you roll two dice. When you bet on a “snake eyes”, meaning a 1 on both dice, you win $30 for each $1 you bet. Otherwise, you lose your dollar. What is the probability of winning this bet? What is the expected value of making this bet? If you play this game 100 times, how much would you expect to lose?
In the game of craps, people bet on the outcome of the throw of two, six-sided...
In the game of craps, people bet on the outcome of the throw of two, six-sided dice. Specifically, wagers are placed on the sum of the outcome on the upward facing number on each of the two dice. We are going to discuss relative likelihoods by counting the number of ways (the number of microstates) associated with specific sums (the macrostate). A. How many microstates are associated with a throw summing to 4? B. How many microstates are associated with...
Write a modular program to simulate the Game of Life and investigate the patterns produced by...
Write a modular program to simulate the Game of Life and investigate the patterns produced by various initial configurations. Some configurations die off rather rapidly; others repeat after a certain number of generations; others change shape and size and may move across the array; and still others may produce ‘gliders’ that detach themselves from the society and sail off into space! Since the game requires an array of cells that continually expands/shrinks, you would want to use multi-dimensional arrays and...
Write a MATLAB program to simulate the Stuck in the Mud game, The following link contains...
Write a MATLAB program to simulate the Stuck in the Mud game, The following link contains the detail game description: https://www.activityvillage.co.uk/stuck-in-the-mud , with additional features that can: • Use five (5) 6-sided dice to automatically play the Stuck in the Mud game against a player. • Greet the player when the game starts. • Let the player to choose the number of rounds to play. Take care of the user input to ensure the program will not crash with inputs...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice is equal to 7 or 11, the player wins immediately....
Write a program in PYTHON for a (very) rudimentary shooter "game". You are the only shooter...
Write a program in PYTHON for a (very) rudimentary shooter "game". You are the only shooter and you start with ammo of 10. The one enemy doesn't shoot back and starts with health of 5. Code a custom function named shoot that prints "Shot fired" and returns True for a hit or False for a miss. Generate a random 0 to assign False or 1 to assign True. In the main function, use a while loop that runs the shoot function...
Python: Write a program to simulate the purchases in a grocery store. A customer may buy...
Python: Write a program to simulate the purchases in a grocery store. A customer may buy any number of items. So, you should use a while loop. Your program should read an item first and then read the price until you enter a terminal value (‘done’) to end the loop. You should add all the prices inside the loop. Add then a sales tax of 8.75% to the total price. Print a receipt to indicate all the details of the...
Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. 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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT