Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON import random def quietCraps(): dice1=random.randint(1,6) dice2=random.randint(1,6) roll = dice1+dice2 if dice1 + dice2 == 7 or dice1 + dice2 == 11: return 1 elif

PYTHON

import random def quietCraps(): dice1=random.randint(1,6) dice2=random.randint(1,6) roll = dice1+dice2 if dice1 + dice2 == 7 or dice1 + dice2 == 11: return 1 elif dice1 + dice2 == 2 or dice1 + dice2 == 3 or dice1 + dice2 == 12: return 0 else: while True: dice1=random.randint(1,6) dice2=random.randint(1,6) if dice1 + dice2 == roll: return 1 elif dice1+dice2==7: return 0

1. implement a function testCraps that takes a positive integer n as a parameter, simulates n games of craps using the quietCraps function, and returns the fraction of games the player won. This function should not include the code and/or logic from the quietCraps function. Instead it should call that function. The following shows several sample runs of the function.

>>> random.seed(5)

>>> testCraps(10)

0.3

>>> random.seed(5)

>>> testCraps(100)

0.44

>>> random.seed(5)

>>> testCraps(1000)

0.497

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions