Question: 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
Get step-by-step solutions from verified subject matter experts
