Use a function from the random library to simulate rolling dice. Write a function that rolls a single die and then use that function to build a program that let's the user play craps. The basic rules of craps are:

1. A player rolls two six-sided dice and adds the numbers rolled together.
2. On this first roll, a 7 or an 11 automatically wins, and a 2, 3, or 12 automatically loses, and play is over. If a 4, 5, 6, 8, 9, or 10 are rolled on this first roll, that number becomes the "point.”
3. The player continues to roll the two dice again until one of two things happens: either they roll the "point" again, in which case they win; or they roll a 7, in which case they lose.

Playing craps can include a number of variations on this game, and also typically involves betting on various outcomes.

Have some fun with different library functions by figuring out how to get Python to:

- Print out a calendar of the month you were born
- Tell you how many days it is until your next birthday
- What day of the week was the Declaration of Independence ratified by the Continental Congress? (write a program that prints out Monday, Tuesday, etc)

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import random

def roll_dice(n):
    roll = [random.randint(1,6) for i in range(n)]
    total = sum(roll)
    print("Player rolls "+str(roll)+" = "+str(total))
    return total

print("*** CRAPS GAME ***")

total = roll_dice(2)
if total in [7, 11]:
    print("Player automatically wins!")
elif total in [2, 3, 12]:
    print("Player automatically loses!")
    point = total
    while True:...

By purchasing this solution you'll be able to access the following files:

for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats