Craps In Python

  • 5 Contributors
  • forum5 Replies
  • 1 Day Discussion Span
  • commentLatest PostLatest Postby snippsat

Recommended Answers

Craps in python

All 5 Replies


Planning Strategies¶

  • 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?
Craps python github
  • 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.
  • 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 Python Github




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Tools matter!!!

Ordinary Differential Equation (ODE) by Python

dav1d 0.1.0 release: The first benchmarks

Bobbie Breckenridge Thanks for Following Us on Twitter!

Mayday Messaging is the first app using Booster

Creating Microservices With Go- Part 1

Purely Functional Python With Static Types

TheFork Technical Platform challenges for non tech people

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


More from Medium

Looping in python

Python Notes

Add comment in a code!

NumPy: Library for the Python programming language.

Python 3 vs Python 2- Which Version to Code in?