Craps Python Program

Craps Python Program 7,4/10 2933 votes

Planning Strategies¶

  1. Python Craps Coding
  2. Blackjack Python Program

The official dedicated python forum. Print ' print 'Here are the rules for this version of Craps.' Print ' (1) You start with 0, and you make your first bet. The code is running a game of craps where on the first roll if I get a 7 or 11 I win, or if I get a 2,3,12 I lose. Browse other questions tagged python python-3.x.

After each round, the program should ask the user if he/she wants to continue playing. The game continues until the player runs out of money, or the player chooses to exit.

Similar to Rock Paper Scissors (as well as any multi-step, complex program), planning out your code will be highly beneficial in writing cleaner and more organized solutions. However, this time, you will be coming up with your own functions. Please remember to heed the following guidelines:
  • The majority of your program should be functions. Break the game down into simple steps or instructions - each of those will have its own function.
  • Each function should have a single purpose. If you find that you have written a function that is doing multiple things, it means you should break it down further into more functions. It’s okay to refactor code mid-development!
  • The one exception to the above should be your main game function, which will contain the game loop, as well as any persistent variables. Try to keep this one as small as possible, utilizing functions as much as you can.
  • Take advantage of return statements. Your code should not have any global variables. Data should be passed to functions through arguments, and from functions through the return statement.
  • Which variables will you have to keep track of during all the rounds, and after all the rounds are completed? Make a note of which ones should be initialized outside of your loop.
  • Be sure to provide the player with the appropriate prompts, letting them know their options and limitations for input.
  • Consider what control structures are necessary for the program.
  • Consider the order of occurrences - what should the program do first?

However, unlike Rock Paper Scissors, in this lab you will be required to validate user’s inputs. This means that:

  • Players should not be able to enter a negative number as a bet
  • Players should not be able to bet more money than they have in their bank
  • Players should not be able to bet decimal amounts of money - only whole numbers. (recall: A boolean to check if x is an integer or not would be: xint(x). This will return True is x is an integer and False otherwise. It works because of math.)
  • When prompted with the choice of ending the game or continuing, the question should repeat until the user has entered one choice or the other.

This also means that your labs will have quite a few while loops. Keep that in mind!

A good place to start would be to write the functions that you plan on writing. You do not need to write the code itself, only the purpose of each function. Here are a few examples:
  • function name: roll2dice
    • arguments: none
    • purpose: generates a random dice roll for two dice and prints out that the two rolls are
    • returns: the sum of the dice roll
  • function name: get_bet
    • arguments: bank amount
    • purpose: to get the amount to be bet from the user. Bet must be a positive integer and no more than they have in their bank. Should repeatedly ask the user to make a bet until they enter a valid one
    • returns: the chosen valid bet amount

And so on. The above are examples, and do not have to be followed. There are many ways these games can be organized. However, notice that the names of my functions are verbs - just remember that functions should do things, and therefore have names that reflect what they do.

You should name your file FILN_craps.py, where FILN is your first initial and last name, no space.

ewoks4life
Hi there,
I had an idea for a new Craps prop bet and was trying to write some Python code that would simulate the bet, but ran into an issue.
My assumption was that if you flipped the rules of a bet and you flipped the payouts of the bet the house edge on that new hypothetical bet could be expressed by simply changing the sign of the house edge on the original bet.
Say you turned the hard 8 bet into a lay the hard 8 bet. You win on 7 or easy 8 before the next hard 8. You’re essentially acting like the casino at that point and the payouts go from 9:1 to 1:9. Shouldn’t the house edge on this new hypothetical bet be -9.09% since the house edge on hard 8 is 9.09%?
To test my assumption, I ran a 10 million round simulation of the traditional hard 8 bet and laying the hard 8 and was surprised to find that while the original hardway bet did show a house edge of ~ 9%, laying the hard 8 showed a house edge of ~ -1%.
I’m trying to determine if the mistake I’ve made is in the assumption that a house edge flips if you flip the payouts and the rules of the bet or if the mistake I’ve made is in the Python code I’ve written.
Any thoughts?

Returns:
Hard eight player edge: -9.11%
Lay hard eight player edge: 0.98%
ThatDonGuy
Your code appears correct.
Your mistake is, while you are 'acting like the casino' when you lay the bet, the casino is betting 1/9 against your 1, rather than 1 against your 9, but your house edge is based on your bet rather than the casino's.
ewoks4life
I'm sorry but I really don't understand what you mean. Are you saying that this bet really would only be an advantage of 1% if the player could make it? I don't see how that could be.
If the casino has a 9% advantage on a hard 8, surely the player would have a 9% advantage if they could book the same exact bet as the casino, right? Putting my $9 up against the casino's $1 (which is the same scenario that plays out on a standard hard 8 bet, just reversed) is the same as putting my $1 up against the casino's $(1/9).
odiousgambit
fair odds are 10:1 ... I'd guess if they ever let you play darkside you'd put up something like $15 to win $1
if you only had to put up $9 I agree that the player would get the casino's exact edge for himself

Python Craps Coding

in any case that has to be the most unheard of bet in a casino - to take the large end of the bet. I can't think of anything like that for the moment
I take it back, the most unheard of thing is to intentionally allow a bet with a player edge
the next time Dame Fortune toys with your heart, your soul and your wallet, raise your glass and praise her thus: “Thanks for nothing, you cold-hearted, evil, damnable, nefarious, low-life, malicious monster from Hell!” She is, after all, stone deaf. ... Arnold Snyder
RSCraps
Thanks for this post from:

I'm sorry but I really don't understand what you mean. Are you saying that this bet really would only be an advantage of 1% if the player could make it? I don't see how that could be.
If the casino has a 9% advantage on a hard 8, surely the player would have a 9% advantage if they could book the same exact bet as the casino, right? Putting my $9 up against the casino's $1 (which is the same scenario that plays out on a standard hard 8 bet, just reversed) is the same as putting my $1 up against the casino's $(1/9).

Craps
'House Edge' is actually a bit of a misnomer.
The casino isn't betting $1 against your $1. The casino is betting $9 against your $1. You just have a 9% disadvantage.
The casino has a 1% or so advantage on their $9 bet. You have a 9% (or so) disadvantage on your $1 bet.
IE: Player $1 bet: has 10 ways to lose $1 and 1 way to win $9. The total money wagered is $11. The sum of outcomes (10*-1 + 1*9) is -1.
-1/11 ~ -9%
The casino, on the other hand, is betting $9. 1 way to lose $9 and 10 ways to win $1. Total money wagered is $99. The sum of outcomes (-9*1 + 1*10) is +1.Python
Craps Python Program+1/99 ~ +1%.

Blackjack Python Program

ThatDonGuy
Thanks for this post from:

'House Edge' is actually a bit of a misnomer.
The casino isn't betting $1 against your $1. The casino is betting $9 against your $1. You just have a 9% disadvantage.
The casino has a 1% or so advantage on their $9 bet. You have a 9% (or so) disadvantage on your $1 bet.


This. +1. Whatever the term for 'exactly' is this week.
The amount of the house edge is the same on both sides of the place bet because you are putting up 9x what the casino is.
The percentage, on the other hand, is different because each side is betting a different amount.
ewoks4life
Blackjack python programThank you both for the explanation. It's much clearer now. I looked over the code 10x and knew it was making the bet and payouts in the exact opposite way so figured it must have just been my lack of understanding the math.

in any case that has to be the most unheard of bet in a casino - to take the large end of the bet. I can't think of anything like that for the moment
I take it back, the most unheard of thing is to intentionally allow a bet with a player edge


When it comes table games I think Craps has the largest lay bet available at 19 to 41 when laying the 4 or 10 (when factoring in the vig). I can't think of anything with a smaller payout compared to the original bet.
You can lay much higher odds on sports. The infamous No Safety SB bet comes to mind.
This is just a thought experiment for me, not a serious idea that I'm going to try to sell to casinos or anything. They wouldn't want this bet. Obviously if a casino did implement this it would not be at 1 to 9. It would be at 1 to 10 or 1 to 11. Much like how 99% of sports betters don't lay -900 on No Safety in the SB, 99% of players would never lay 1 to 9 on a bet at a Craps table even if they had an advantage so no players would ever lay 1 to 10 or 1 to 11 on a bet where the casino had an advantage so it would just never be implemented.
I'm just messing around trying to intersect my interest in (basic) programming with my interest in gambling.
Comments are closed.