Craps Python Program

Output: Creating Stopwatch using Tkinter. Now lets try to create a program using Tkinter module to create a stopwatch. A stopwatch is a handheld timepiece designed to measure the amount of time elapsed from a particular time when it is activated to the time when the piece is deactivated. Se how i have small functions that dos a specific task,and not one big main function with all code. You only reach phase 2 function if dice sum is in (4,5,6,8,9,10). Where you can code some stuff for phase 2.

I have spent a lot of time on this code, and simply cannot figure it out logically, and every move I make seems to be a wrong step. Any help will be greatly appreciated. A sample run of the code should look like this: This program simulates a game of craps using Python’s random module. Would you like to play? 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.

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:

Editedby Dani because:Formatting fixed
  • 2 Contributors
  • forum2 Replies
  • 944 Views
  • 1 Day Discussion Span
  • commentLatest PostLatest Postby CFrances

Recommended Answers

First, the usual rejoinder: use the ' and '[/code ]' tags to make your posts look pretty.

Now for the code: why not turn main() into a function called game() that returns True for a win and False for a loss. Then you can run a for loop and add …

Jump to Post

All 2 Replies

First, the usual rejoinder: use the ' and '[/code ]' tags to make your posts look pretty.

Now for the code: why not turn main() into a function called game() that returns True for a win and False for a loss. Then you can run a for loop and add up the True's (which have a value of 1).

Jeff[code=Python ]' and '[/code ]' tags to make your posts look pretty.

Craps Python Program

Now for the code: why not turn main() into a function called game() that returns True for a win and False for a loss. Then you can run a for loop and add up the True's (which have a value of 1).

Jeff

Planning Strategies¶

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 Python ProgramCraps Python Program
  • 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

Blackjack Python Program

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.

Python Craps Coding

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