Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 6 - Functions - Programming Exercises - Page 211: 6.30

Answer

code

Work Step by Step

# 6.30 (Game: chance of winning at craps) Revise Exercise 6.28 to run it 10,000 times # and display the number of winning games. from random import random def main(): winCount = 0 for i in range(10000): dice = getDice() if dice == 7 or dice == 11: winCount += 1 elif dice == 2 or dice == 3 or dice == 12: winCount += 0 else: point = dice dice = getDice() # print("point is " + str(point)) while dice != 7 and dice != point: dice = getDice() if dice != 7: winCount += 1 print(winCount) # Get a dice def getDice(): i1 = random.randint(1, 6) i2 = random.randint(1, 6) # print("You rolled " + str(i1) + " + " + str(i2) + " = " + str(i1 + i2)) return i1 + i2 main()
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.