Answered step by step
Verified Expert Solution
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started