Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import random# Request the inputdollars = int(input(How many dollars do you have? ))# Initialize variablesmaxDollars = dollarscountAtMax = 0count = 0# Loop until the money

import random# Request the inputdollars = int(input("How many dollars do you have? "))# Initialize variablesmaxDollars = dollarscountAtMax = 0count = 0# Loop until the money is gonewhile dollars > 0:count += 1# Roll the dicedie1 = random.randint(1, 6)# 1-6die2 = random.randint(1, 6)# 1-6#Calculate the winnings or lossesif die1 + die2 == 7:dollars += 4else:dollars -= 1#If this is a new maximum, remember itif dollars > maxDollars:maxDollars = dollarscountAtMax = count# Display the resultsprint("You are broke after " + str(count) + " rolls. " + \"You should have quit after " + str(countAtMax) + \" rolls when you had $" + str(maxDollars) + ".")

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

Pre Algebra Practice Workbook The Most Comprehensive Review Of Pre Algebra

Authors: Reza Nazari

2024th Edition

1637195591, 978-1637195598

More Books

Students also viewed these Mathematics questions