I am a beginner programmer and I need help with some parts of my code. I am currently creating a craps game simulator, but it appears that my code wont really run. My code is attached and for a few notes, every time there is a roll of the dice, the user must hit enter which will cause the program to roll the dice.
For a brief overview, here is some of the rules behind craps:
Each round has two phases: "come-out" and "point". To start a round, the shooter makes one or more "come-out" rolls. A come-out roll of 2, 3 or 12 loses and is called "crap-out". A come-out roll of 7 or 11 (a "natural") wins. The other possible numbers are the point numbers: 4, 5, 6, 8, 9, and 10. If the shooter rolls one of these numbers on the come-out roll, this establishes the "point" and continues to the point phase. At the point-phase, if the user rolls the same number as the come-out phase, they "Hit" or win the game. If they roll a 7 however, they "seven-out" or lose the game. If the player doesn't get a 7 or the same come-out number, they keep rolling until they either hit or seven-out.
My issue is that when the program runs, i am able to get Please hit enter, but when I hit enter, it wont continue to the next part of the code which will roll the dice. I can't quite figure out why that happens. Also, I may need some help looking at the logic behind my code, I am not entirely sure if when implemented, the desired results would occur. Any help is appreciated!
import random
def playRound():
#This will print out the current phase.
print "The come-out phase:"
print
#This will tell the user to hit enter to roll the dice.
rollDice = raw_input("Hit ENTER to roll the dice...")
#this will ensure that when a user hits enter, the program moves on.
if rollDice == rollDice:
#this will sum up two random integers to simulate two dice being thrown and record the total.
diceTotal = random.randint(1,6) + random.randint(1,6)
#this will see if the numbers are 7 or 11, and if so, will let the user know they won.
if diceTotal in (7,11):
return "You rolled a", diceTotal
return "You Win: Natural!"
#this will see if numbers are 2, 3, or 12, and if so, will let user know they lost.
if diceTotal in (2,3,12):
return "You rolled a", diceTotal
return "You Lose: Crap-Out!"
#let user know what they rolled if conditions above are not met.
return "You Rolled a", diceTotal
#This will now start the point phase.
print "The Point Phase:"
print
#this will ask the user to hit enter to roll the dice.
rollDice = raw_input("Hit ENTER to roll the dice...")
#this will ensure that when the user hits enter, the dice will roll.
if rollDice == rollDice:
#this will add up the sum of two random numbers simulating dice and save to variable.
diceTotalPoint = random.randint(1,6) + random.randint(1,6)
#this will see if the roll is not 7 or the diceTotal from come-out phase.
while diceTotalPoint not in (7, diceTotal):
#This will continue to roll the dice, if 7 or the come-out phase number is not achieved.
rollDice = raw_input("Hit ENTER to roll the dice...")
if rollDice == rollDice:
diceTotalPoint = random.randint(1,6) + random.randint(1,6)
#this will tell the user that if the dice roll is the same as the come-out phase, it will be a hit and they win.
if diceTotalPoint == diceTotal:
return "You Rolled a", diceTotalPoint
return "You Win: Hit!"
#this will tell the user if they get a 7, and tell them they lose.
if diceTotalPoint == 7:
return "You Rolled a", diceTotalPoint
return "You lose: Seven-Out!"