In: Computer Science
Please generate code in PYTHON:
In the game of Lucky Sevens, the player rolls a pair of dice. If the dots add up to 7, the player wins $4; otherwise, the player loses $1.
Suppose that, to entice the gullible, a casino tells players that there are lots of ways to win: (1, 6), (2, 5), and so on. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because many people’s eyes glaze over at the first mention of mathematics, your challenge is to write a program that demonstrates the futility of playing the game.
Your program should take as input the amount of money that the player wants to put into the pot, and play the game until the pot is empty. At that point, the program should print:
An example of the program input and output is shown below:
How many dollars do you have? 50 You are broke after 220 rolls. You should have quit after 6 rolls when you had $59
CODE IN PYTHON:
#importing random module to generate random number
import random
#taking input from the user
amount = input("How many dollars do you have?")
amount = int(amount)
maxAmount = amount
maxSteps = 0
numberOfSteps = 0
while(amount!=0):
numberOfSteps += 1
dice1 = random.randrange(1,7)
dice2 = random.randrange(1,7)
if(dice1+dice2==7):
amount += 4
else:
amount -= 1
if(amount>maxAmount):
maxAmount = amount
maxSteps = numberOfSteps
#displaying result
print("You are broken after "+str(numberOfSteps)+" rolls")
print("You should have quit after "+str(maxSteps)+" rolls when you
had "+str(maxAmount))
INDENTATION:
OUTPUT: