import random
#Simulate the roll of a single die.
def die():
return random.randint(1,6)
#Return the sum of two dice.
#Observe that 2*die() is not
#the same as die()+die()
def dice():
return die()+die()
#In the simplest version of the craps game, the bettor bets
#$1. If 7 or 11 is rolled, he wins a dollar (i.e., he gets
#back his bet plus an additional dollar). Otherwise, he loses
#his dollar. This function returns 1 or -1 accordingly.
def round_of_craps0():
roll=dice()
if roll==7 or roll==11:
return 1
else:
return -1
#In this version of the game, we use the real casino rules
#for a 'Pass line' bet. If the roll is 7 or 11, the bettor wins.
#If it is 'craps'---2,3 or 12, they lose. Otherwise, the value
#rolled is the 'point'. The dice are then rolled again until
#either the point reappears (win $1) or 7 appears lose $1).
def round_of_craps1():
firstroll=dice()
#print( firstroll)
if firstroll==2 or firstroll==3 or firstroll==12:
return -1
elif firstroll==7 or firstroll==11:
return 1
else:
while True:
newroll=dice()
#print (newroll)
if newroll==7:
return -1
elif newroll==firstroll:
return 1
#play with an opening stake for n rounds, or until you run out of money
#report amount remaining at each round. Try this out with each version
#of the game.
def play(stake,n):
for r in range(n):
stake+=round_of_craps1()
#print(r,stake)
if stake<1:
break
print()
print(r,stake)