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?
Using Python, Assignment Write a program that plays a game of craps. The program should allow...
Using Python, Assignment Write a program that plays a game of craps. The program should allow the player to make a wager before each “turn”. Before each turn, allow the user to either place a bet or exit the game. After each turn display the player’s current balance. Specifics Each player will start with $500.00. Initially, and after each turn give the user the option of betting or leaving the program. Implement this any way you wish, but make it...
Write a C++ program to play the dice game "Craps". Craps is one of the most...
Write a C++ program to play the dice game "Craps". Craps is one of the most popular games of chance and is played in casinos and back alleys throughout the world. The rules of the game are straightforward: A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the...
Write a Python program to simulate a very simple game of 21 •Greet the user. •Deal...
Write a Python program to simulate a very simple game of 21 •Greet the user. •Deal the user a card and display the card with an appropriate message. •Deal the user another card and display the card .•Ask the user if they would like a third card. If so, deal them another card and display the value with an appropriate message. •Generate a random number between 10 and 21 representing the dealer’s hand. Display this value with an appropriate message....
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...
In the game of craps, a pass line bet proceeds as follows: Two six-sided dice are...
In the game of craps, a pass line bet proceeds as follows: Two six-sided dice are rolled; the first roll of the dice in a craps round is called the “come out roll.” A come out roll of 7 or 11 automatically wins, and a come out roll of 2, 3, or 12 automatically loses. If 4, 5, 6, 8, 9, or 10 is rolled on the come out roll, that number becomes “the point.” The player keeps rolling the...
Python: Write a program that keeps track of a game score and declares the winner when...
Python: Write a program that keeps track of a game score and declares the winner when the game is over. A game is over when either one player scores 10 or more points with at least 2 more points than the opponent. A game is also over when one player scores 7 points and the opponent scores none. The program should begin by asking the names of the two players. Then, it should keep asking who won the point till...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT