Question

In: Computer Science

Please generate code in PYTHON: In the game of Lucky Sevens, the player rolls a pair...

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:

  1. The number of rolls it took to break the player
  2. The maximum amount of money in the pot.

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

Solutions

Expert Solution

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:


Related Solutions

PLEASE USE PYTHON THANK YOU In the game of Lucky Sevens, the player rolls a pair...
PLEASE USE PYTHON THANK YOU 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 many ways to win: (1, 6), (2, 5), and soon. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because many people's eyes...
In the game of Lucky Sevens, the player rolls a pair of dice. If the dots...
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...
In the game of Lucky Sevens, the player rolls a pair of dice. If the dots...
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 many ways to win: (1, 6), (2, 5), and soon. 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...
At a charity event, a player rolls a pair of dice. If the player roles a...
At a charity event, a player rolls a pair of dice. If the player roles a pair (same number on each die), the player wins $10. If the two are exactly one number a part (like a five and a six), the player wins $6. IF the player roles a one and a six, they win $15. Otherwise, they lose. If it cost $5 to play, find the expected value. Write a complete sentence to explain what your answer means...
PYTHON GAME OF PIG The game of Pig is a simple two player dice game in...
PYTHON GAME OF PIG The game of Pig is a simple two player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn a player rolls a six-sided die. After each roll: a) If the player rolls a 1 then the player gets no new points and it becomes the other player’s turn. b) If the player rolls 2-6 then they can either roll again or hold. If the player...
1)A casino wants to introduce a new game. In this game a player rolls two 4-sided...
1)A casino wants to introduce a new game. In this game a player rolls two 4-sided dice and their winnings are determined by the following rules: Otherwise, the player wins nothing. If 3 ≤ sum ≤ 5 the player wins $25. If sum ≥ 6 the player wins $100. a)Determine the probability distribution for this gamble. Probability Distribution X P (X) b)How much should the casino charge for this game if they want to make a profit in the long...
Please write a scheme code for the rock paper scissors game between a player and the...
Please write a scheme code for the rock paper scissors game between a player and the computer (AI). In scheme programming language please.
You are rolling a pair of balanced dice in a board game. Rolls are independent. You...
You are rolling a pair of balanced dice in a board game. Rolls are independent. You land in a danger zone that requires you to roll doubles (both faces show the same number of spots) before you are allowed to play again. 1. What is the probability of rolling doubles on a single toss of the dice? A) 25/36 B) 5/36 C) 1/6 D) 1/36 2. What is the probability that you do not roll doubles on the first toss,...
In a dice game a player first rolls two dice. If the two numbers are l...
In a dice game a player first rolls two dice. If the two numbers are l ≤ m then he wins if the third roll n has l≤n≤m. In words if he rolls a 5 and a 2, then he wins if the third roll is 2,3,4, or 5, while if he rolls two 4’s his only chance of winning is to roll another 4. What is the probability he wins?
A game works as follows: the player rolls one dice once (let's call it ''n'') and...
A game works as follows: the player rolls one dice once (let's call it ''n'') and then he rolls it second time (let's call this second roll "m'') and receives nm points . A)What is the probability that n = 1 knowing that the player has received more than 20 points. b) What is the probability that m = 1 knowing that the player has received more than 20 points. c) (What is the probability that the player receives more...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT