def crapsGame(): # PROBLEM 3. # In the game of craps, the player (\'shooter\') t
ID: 3555265 • Letter: D
Question
def crapsGame():
# PROBLEM 3.
# In the game of craps, the player ('shooter') throws
# two standard six-sided dice repeatedly. On the first
# throw, the shooter wins on 7 or 11 (a 'natural') and
# loses on 2, 3 or 12 ('craps'). Create lists that define
# the losing and winning first throw combinations.
# PROBLEM 4. Make the first throw.
# Call dieThrows() to simulate the shooter's first throw of
# two dice. If the throw is 2, 3 or 12, print a loser's message
# to the shooter and return 'L'. If the throw is 7 or 11 print a
# winner's message to the shooter and return 'W'.
Explanation / Answer
Dice throw program
import random
def dice4():
min=1
max=4
print random.randint(min, max);
return;
def dice6():
min=1
max=6
print random.randint(min, max);
return;
def dice12():
min=1
max=12
print random.randint(min, max);
return;
roll = "yes"
y = 1
while roll == "yes" or roll == "y":
x = input("What dice do you want to use? 4/6/12?");
if x ==8:
dice4();
elif x==12:
dice6();
elif x==16:
dice12();
else:
print "You have not entered a valid dice number";
roll = input("Do you want to roll again? y/n");
print "Thanks for rolling!";
input("Press <Enter> to quit");
import random
def dice(sides=6):
return random.randint(1, sides)
def get_names():
playerOne = raw_input("Enter the first player's name: ")
playerTwo = raw_input("Enter the second player's name: ")
return playerOne, playerTwo
def dice_game(playerOne, playerTwo):
# playerOne rolls a single six-sided die.
rollOne = dice()
# So does playerTwo.
rollTwo = dice()
# The winner is the one who gets a higher number.
if rollOne > rollTwo:
return playerOne
elif rollTwo > rollOne:
return playerTwo
else:
# They must have rolled equal, so a draw.
return ""
def displayWinner(winner):
print "And the winner is: ",
if winner == "":
print "... the game is a draw!"
else:
print winner
print
def main():
playerOne, playerTwo = get_names()
play_again = True
while play_again:
print "Rolling dice..."
winner = dice_game(playerOne, playerTwo)
displayWinner(winner)
answer = raw_input("Would you like to play again? (y/n) ")
play_again = answer.strip().lower() in ('y', 'yes')
main()
from random import randint
def roll(sides, number_of_dice):
"""Rolls Dice."""
return [randint(1, sides) for i in range(num_of_dice)]
prompt = """
Would you like to roll the same combination of dice {}?
Please type 'yes', 'no', or 'quit'
"""
# Main Program
name = raw_input(" Please tell me your name > ")
print """
Hello {} and welcome to an RPG Dice Roller by Ray Weiss.
Please type quit when prompted to exit or use CNTRL-C.
Thanks to everyone at Stack Overflow etc. for the help.
""".format(name)
sides = input(" How many sides do you want on your dice? > ")
num_of_dice = input(" How many {} sided dice do you want to roll? >".format(sides))
results = roll(sides, num_of_dice)
print results
roll_again = raw_input(prompt.format(name))
while True:
if roll_again == "yes":
results = roll(sides, num_of_dice)
print results
roll_again = raw_input(prompt.format(name))
if roll_again == "no":
sides = input("How many sides do you want on your dice? > ")
num_of_dice = input(" How many {} sided dice do you want to roll? >".format(sides))
results = roll(sides, num_of_dice)
print results
roll_again = raw_input(prompt.format(name))
if roll_again == "quit":
print """
Thank you {} for using! Goodbye!
""".format(name)
break
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.