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 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...
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...
In this python program , you are to build a trivia game. The game should present...
In this python program , you are to build a trivia game. The game should present each question – either in order or randomly – to the player, and display up to four possible answers. The player is to input what they believe to be the correct answer.   The game will tell the player if they got it right or wrong and will display their score. If they got it right, their score will go up. If they got it...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: You can set these constant global variables at the top outside of your main function definition: COMPUTER_WINS = 1 PLAYER_WINS = 2 TIE = 0 INVALID = 3 ROCK = 1 PAPER = 2 SCISSORS = 3 For this program 1 represents rock, 2 represents paper, and 3 represents scissors. In...
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT