Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Python 3.6.4: Craps is a dice game played at many casinos. A player rolls a pair of normal six-sided dice. If the initial roll

Using Python 3.6.4:

Craps is a dice game played at many casinos. A player rolls a pair of normal six-sided dice. If the initial roll sums up to 2, 3, or 12, the player loses. If the roll is 7 or 11, the player wins. Any other initial roll causes the player to "roll for point" which means that the player keeps rolling the dice until either rolling a 7 or re-rolling the value of the initial roll. If the player re-rolls the initial value before rolling a 7, it's a win for the player. Rolling a 7 first is a loss. Write a program that will simulate multiple games of craps and return the fraction of games that the player won. I suggest your organize your program as follows:

  1. Write a function forPoint that takes as input an initial roll (i.e. an integer between 2 and 12) and repeatedly generates rolls of a pair of dice until either the value of the roll is 7 (in which case 0 is returned) or the value of the roll is the initial roll (in which case 1 is returned).
  2. Write a function craps that takes no argument and simulates one game of craps. The program will first roll a pair of dice. If the value (sum of two dice) of the roll obtained is 7 or 11, then 1 is returned by craps(). If the value obtained is 2, 3 or 12, then 0 is returned by craps(). For all other roll values, forPoint(value) is called and the value returned by it is returned by craps. In other words, craps() returns 1 if the player won, 0 otherwise.
  3. Write a function testCraps that takeas a positive integer n as input, simulates n games of craps and returns the fraction of games the player won.

Usage: >>> forPoint(2) 0 >>> forPoint(2) 0 >>> forPoint(2) 1 >>> craps() 1 >>> craps() 0 >>> testCraps(10000) 0.4806 >>> testCraps(10000) 0.4978 >>> testCraps(10000) 0.4901

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions

Question

Evaluate three pros and three cons of e-prescribing

Answered: 1 week ago

Question

5. Prepare for the role of interviewee

Answered: 1 week ago

Question

6. Secure job interviews and manage them with confidence

Answered: 1 week ago