the program below simulates a game of craps and its pretty much done except for a way to get the while loop to stop. i was trying to get an input from the user when they wanted to stop rolling and to enter "n" for no but im not sure how to do it. the idea i had is in the commented out region near the top of the code. i tested it and when i enter "n" for no it kept going as if i was still entering "y" for yes. any advice/help is appreciated.

#
# PURPOSE: simulates the casino game craps
#
# INPUT(S): none
#
# OUTPUT(S): results of your dice rolls and if you won or lost
#
# EXAMPLES: 
#           
#
################################################################################
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
##        while going == 'n' or going == 'N':
##            break
        
        if roll in [2,3,12]:
            print die1, die2
            print 'You lose'
            going = raw_input('Play again "y" for yes "n" for no: ')
        elif roll == 7 or roll == 11:
            print die1, die2
            print 'You win'
            going = raw_input('Play again "y" for yes "n" for no: ')
        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 True:
            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 "n" for no: ')
            elif roll2 == 7:
                print 'You lose'
                going = raw_input('Play again "y" for yes "n" for no: ')

        
main()

This is what you need to add at the end of the while true :

while True:
            #...OMITTED

            
            #this is what you can add to fix the problem
            if going.lower() == "n":
                break

I don't know the rules of craps well, but shouldn't the code be written like this:

import random

def main():
    going = 'y'
    while going.lower() == '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

        print die1,die2
        
        if roll in [2,3,12]:
            print 'You lose'
            going = raw_input('Play again "y" for yes "n" for no: ')
        elif roll in [7,11]:
            print 'You win'
            going = raw_input('Play again "y" for yes "n" for no: ')
        else:
            print 'You must get a',roll,'to win'
            going = "n"
            raw_input('Press "Enter" to roll the dice')

        if going.lower() == "y":
            continue
   
        while True:
            die3 = random.randint(1, 6)
            die4 = random.randint(1, 6)
            roll2 = die3 + die4
            print die3,die4
            if roll == roll2:
                print 'You Win!!!'
                going = raw_input('Play again "y" for yes "n" for no: ')
                break
            elif roll2 == 7:
                print 'You lose'
                going = raw_input('Play again "y" for yes "n" for no: ')
                break

main()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.