Python 3.6 It has to execute 10,000 times Craps is a popular dice game played in
ID: 3847771 • Letter: P
Question
Python 3.6
It has to execute 10,000 times
Craps is a popular dice game played in casinos. Write a program to play a variation of the game, as follows: Roll two dice. Each die has six faces representing values 1, 2...6, respectively. Check the sum of the two dice. If the sum is 2, 3, or 12 (called craps), and you lose;if the sum is 7 or 11 (called natural), you win;if the sum is any value (i.e., 4, 5, 6, 8, 9, or 10), a point is established. Continue to roll the dice until either a 7 or the same point value is rolled. If 7 is rolled, you lose. Otherwise, you win. Your program acts as a single player. Here are some sample runs. You rolled 5 + 6 = 11 You win You rolled 1 + 2 = 3 You lose You rolled 4 + 4 = 8 point is 8 You rolled 6 + 2 = 8 You win You rolled 3 + 2 = 5 point is 5 You rolled 2 + 5 = 7 You lose Revise the program to run it 10,000 times display the number of winning games. Here is a sample output: The total number of wins for 10,000 rolls is 4891Explanation / Answer
import random
import sys
def play():
print "Welcome to Python Craps!"
print "To start the game, press enter."
raw_input("")
result()
def result():
print "The come-out phase:"
print
raw_input("Hit ENTER to roll the dice...")
d_Total = random.randint(1,6) + random.randint(1,6)
if d_Total == 7 or d_Total == 11:
print "You rolled ", diceTotal
print "You Win!!"
print "Wanna Play again? press 'y' for Yes & 'n' for no."
p = raw_input()
if p=="y" or p=="Y":
result()
elif p=="n" or p=="N":
sys.exit()
else:
result()
elif d_Total == 2 or d_Total == 3 or d_Total == 12:
print "You rolled ", diceTotal
print "You Lose!!"
print "Wanna Play again? Press 'y' for Yes & 'n' for no."
p = raw_input()
if p=="y" or p=="Y":
result()
elif p=="n" or p=="N":
sys.exit()
else:
result()
else:
print "You Rolled ", d_Total
print "The Point Phase:"
print "Your point number is", d_Total
print "You need to roll a", d_Total, "before you roll a 7 to win! If you roll a 7, you lose!"
print "Rolling any other number is okay. You have to keep rolling until you win or lose!"
points(d_Total)
def points(d_Total):
raw_input("Hit ENTER to roll the dice...")
d_Point = random.randint(1,6) + random.randint(1,6)
if d_Point == d_Total:
print "You Rolled ", d_Point
print "You Win!!"
print "Play again? 'y' for Yes &'n' for no."
p=raw_input()
if p=="y" or p=="Y":
result()
elif p=="n" or p=="N":
sys.exit()
else:
result()
elif d_Point == 7:
print "You Rolled ", d_Point
print "You lose!! Seven-Out!"
print "Play again? 'y' for Yes & 'n' for no."
p=raw_input()
if p=="y" or p=="Y":
result()
elif p=="n" or p=="N":
sys.exit()
else:
result()
else:
print "You rolled ", d_Point
print "Roll Again!!"
roll_again(d_Total)
def roll_again(d_Total):
raw_input("Hit ENTER to roll the dice...")
d_Point = random.randint(1,6) + random.randint(1,6)
if d_Point == d_Total:
print "You Rolled ", d_Point
print "You Win!!"
print "Play again? Press 'y' for Yes & 'n' for no."
p=raw_input()
if p=="y" or p=="Y":
result()
elif p=="n" or p=="N":
sys.exit()
else:
result()
elif d_Point == 7:
print "You Rolled ", d_Point
print "You lose!!"
print "Play again? Press 'y' for Yes & 'n' for no."
p=raw_input()
if p=="y" or p=="Y":
result()
elif p=="n" or p=="N":
sys.exit()
else:
resultt()
else:
print "You rolled ", d_PointPoint
print "Roll Again!"
roll_again(d_Total)
play()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.