Craps Test Python

Craps Test Python

Planning Strategies¶

It’s easy to see that craps is a game of odds where possible winning two-dice combinations are compared to possible losing two-dice combinations. Whether numbers are winners or losers depends entirely the type of bets that you make, which we’ll discuss in other articles. I'm new to Python and I'm working on a craps game. I got the basic code down, but I need to simulate a total of 200 games and track the number of wins. I need a counter in my program, but I can't figure out how to do this. Here's what I have so far: import random def roll: die1 = random.randrange.

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:

Craps Test Python Training

  • 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

Craps Test Python Games

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.

Craps Test Python Cheat

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