Craps Python Rating: 4,9/5 1598 votes

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:

Craps in python
Editedby Dani because:Formatting fixed
  • 2 Contributors
  • forum2 Replies
  • 1,052 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 …

An introduction to using pseudocode to write a Craps program in Python. A Python program will see that the command line arguments are assigned to sys.argv as 'casinosim.py', '-g', 'craps'. Argv0 is the name of the main module, the script Python is currently running. When the script in casinosym.py finishes running, the Python interpreter also finishes, and returns a status code of 0 to the operating system.

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.

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

Time again for a game script.

Craps Python

How it works

Python Craps Simulation

This is a classic “roll the dice” program.

We will be using the random module for this,since we want to randomize the numberswe get from the dice.

We set two variables (min and max) , lowest and highest number of the dice.

We then use a while loop, so that the user can roll the dice again.

The roll_again can be set to any value, but here it’s set to “yes” or “y”,
but you can also add other variations to it.

Rolling the dice

Rules Of Craps Game

Recommended Python Training

Dice Game Python Code

For Python training, our top recommendation is DataCamp.