I'm trying to implement a function craps()
that takes no argument, simulates one game of craps, and returns 1
if the player won and 0
if the player lost.
Rules of the game: the game starts with the player throwing a pair of dice. If the player rolls a total of 7 or 11, the player wins. If the player rolls a total of 2,3 or 12, the player loses. For all other roll values the games goes on until the player either rolls the initial value agaian (in which case the player wins) or 7 (in which the player loses).
I think I'm getting closer but I'm not there yet, I don't think I got the while loop working correctly yet. This is the code I got so far:
def craps():
dice = random.randrange(1,7) + random.randrange(1,7)
if dice in (7,11):
return 1
if dice in (2,3,12):
return 0
newRoll = craps()
while newRoll not in (7,dice):
if newRoll == dice:
return 1
if newRoll == 7:
return 0
How do I fix the while loop? I really can't find the issue with it but I know it's wrong or incomplete.