Having trouble with the final loop in this craps program. Any suggestions.
Problem starts on line 28.
Was thinking about breaking the whole thing into functions but I don't exactly know where to call them at. When I do call them I get accessed before argument errors or something to that affect.
Could someone also tell me if there is a way to print spaces without hitting the space bar? Wanted to center the word craps.

import random

def main():
    going = 'y'
    while going == 'y' or going == 'Y':
        print '*' * 30
        print'             CRAPS'
        print '*' * 30
        raw_input('Press "Enter" to roll the dice')
        die1 = random.randint(1, 6)
        die2 = random.randint(1,6)
        roll = die1 + die2
        
        if roll in [2,3,12]:
            print die1, die2
            print 'You lose'
            going = raw_input('Play again "y" for yes: ')
        elif roll == 7 or roll == 11:
            print die1, die2
            print 'You win'
            going = raw_input('Play again "y" for yes: ')
        elif roll in [4,5,6,8,9,10]:
            print die1, die2
            print 'You must get a',roll,'to win'
            raw_input('Press "Enter" to roll the dice')
            

        while roll == roll:
##I tried putting everything under the sun in that while loop.

            die3 = random.randint(1, 6)
            die4 = random.randint(1, 6)
            roll2 = die3 + die4
            print roll2
            if roll == roll2:
                print 'You Win!!!'
                going = raw_input('Play again "y" for yes: ')
            elif roll2 == 7:
                print 'You loose'
                going = raw_input('Play again "y" for yes: ')
main()

Whats wrong, are you getting errors? Or do you just want to make it look cleaner?

Oh and for the spaces, try using something like
print ' '*whatever number,
print 'Craps'

For spacing, try print ' ' * 15 + 'CRAPS' . Also, the word is "lose" not "loose". Where you say while roll == roll: you probably should just say while True: since that is the canonical way of setting up an infinite loop.

Now to get out of the loop once the user enters a character, you only need to add a [B]break[/B] statement after both the going = raw_input(...) statements, at the same indentation level. (I'm not sure that's what you asked for, it wasn't clear, but it seems to me you wanted a way to get out of the while loop.

Sadly, I don't know this game. What does the program supposed to do?
As I see in the program, the player rolls two dices and adds the values.
If the sum is 7 or 11 he wins
If the sum is 2,3,12 he looses
Otherwise he rolls over and over till he gets the original sum or 7. In the first case he wins, in the other loses.

Centering a string in a terminal in a general case requires you to get to know the terminal size. That is complicated. I would use the str.center method instead.

Its just a game of chance. Was having problems with the while statement re looping. Supposed to add the graphics.py module to it later. I don't know if anyone if familiar with that.

your while loop is keep on going I give a value or not it keep on going but I am not sure what kind of help you are seeking can you explain ?

This article has been dead for over six months. Start a new discussion instead.