Question

In: Computer Science

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 glaze over at the first mention of mathematics “wins $4”.

      Your challenge is to write a program that demonstrates the futility of playing the game. Your Python 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.

          The program should have at least TWO functions (Input validation and Sum of the dots of user’s two dice). Like the program 1, your code should be user-friendly and able to handle all possible user input. The game should be able to allow a user to ply as many times as she/he wants.

          The program should print a table as following:

      Number of rolls             Win or Loss                Current value of the pot

                  0                                 Put                                   $10

                  1                                 Win                                  $14

                  2                                 Loss                                  $13

                  3                                 Loss                                  $12

                  ##                              Loss                                  $0

        You lost your money after ## rolls of play.

        The maximum amount of money in the pot during the playing is $##.

        Do you want to play again?

      At that point the player’s pot is empty (the Current value of the pot is zero), the program should display the number of rolls it took to break the player and the maximum amount of money in the pot during the playing.

        Again, add good comments to your program.

        Test your program with $5, $10 and $20.

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 mention of mathematics “wins $4”.

      Your challenge is to write a program that demonstrates the futility of playing the game. Your Python 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.

          The program should have at least TWO functions (Input validation and Sum of the dots of user’s two dice). Like the program 1, your code should be user-friendly and able to handle all possible user input. The game should be able to allow a user to ply as many times as she/he wants.

          The program should print a table as following:

      Number of rolls             Win or Loss                Current value of the pot

                  0                                 Put                                   $10

                  1                                 Win                                  $14

                  2                                 Loss                                  $13

                  3                                 Loss                                  $12

                  ##                              Loss                                  $0

        You lost your money after ## rolls of play.

        The maximum amount of money in the pot during the playing is $##.

        Do you want to play again?

      At that point the player’s pot is empty (the Current value of the pot is zero), the program should display the number of rolls it took to break the player and the maximum amount of money in the pot during the playing.

        Again, add good comments to your program.

        Test your program with $5, $10 and $20.

Solutions

Expert Solution

Program

import random

def playRound(budget: int) -> tuple:
  
sum = sumOfDice(random.randint(1,6), random.randint(1,6))
if sum == 7:
budget += 4
return ("Win",budget)
else:
budget -= 1
return ("Loss",budget)

def sumOfDice(die1: int, die2: int) -> int:
return die1 + die2

def haveMoney(budget: int) -> bool:
# This is a ternary expression it is an if statement in one line
# Truthy Expression Falsy
return True if budget > 0 else False

def main():
numRolls = 0


outputString = "\t{0}\t\t{1}\t\t{2}"

# To prevent a type error, the string is explicitly converted to int
budget = int(input("What is your gambling budget?"))

print("Number of rolls\t\tWin or Loss\tCurrent value of the pot")

print(outputString.format(numRolls, "Put", budget))

# The return value is a boolean type, thus the output is the expression
while haveMoney(budget):
  
numRolls += 1
output = playRound(budget)
budget = output[1]
print(outputString.format(numRolls, output[0], output[1]))

print("Sorry you're out of money")


if __name__ == "__main__":
main()
  
while True:
userIn = input("Would you like to play again?")
if 'yes' == userIn:
main()
else:
print("Goodbye")
break

Output

What is your gambling budget?50
Number of rolls       Win or Loss   Current value of the pot
   0       Put       50
   1       Loss       49
   2       Loss       48
   3       Loss       47
   4       Loss       46
   5       Loss       45
   6       Loss       44
   7       Loss       43
   8       Loss       42
   9       Loss       41
   10       Loss       40
   11       Win       44
   12       Loss       43
   13       Loss       42
   14       Loss       41
   15       Loss       40
   16       Loss       39
   17       Loss       38
   18       Loss       37
   19       Loss       36
   20       Loss       35
   21       Win       39
   22       Loss       38
   23       Win       42
   24       Loss       41
   25       Loss       40
   26       Loss       39
   27       Loss       38
   28       Loss       37
   29       Loss       36
   30       Loss       35
   31       Loss       34
   32       Loss       33
   33       Loss       32
   34       Win       36
   35       Win       40
   36       Loss       39
   37       Loss       38
   38       Loss       37
   39       Loss       36
   40       Loss       35
   41       Loss       34
   42       Loss       33
   43       Loss       32
   44       Loss       31
   45       Win       35
   46       Loss       34
   47       Loss       33
   48       Loss       32
   49       Win       36
   50       Loss       35
   51       Loss       34
   52       Loss       33
   53       Loss       32
   54       Loss       31
   55       Loss       30
   56       Loss       29
   57       Loss       28
   58       Loss       27
   59       Loss       26
   60       Loss       25
   61       Loss       24
   62       Loss       23
   63       Loss       22
   64       Loss       21
   65       Loss       20
   66       Loss       19
   67       Loss       18
   68       Loss       17
   69       Loss       16
   70       Loss       15
   71       Loss       14
   72       Loss       13
   73       Loss       12
   74       Loss       11
   75       Loss       10
   76       Loss       9
   77       Loss       8
   78       Win       12
   79       Loss       11
   80       Loss       10
   81       Win       14
   82       Loss       13
   83       Loss       12
   84       Loss       11
   85       Loss       10
   86       Loss       9
   87       Win       13
   88       Loss       12
   89       Loss       11
   90       Win       15
   91       Loss       14
   92       Loss       13
   93       Win       17
   94       Loss       16
   95       Loss       15
   96       Loss       14
   97       Loss       13
   98       Loss       12
   99       Win       16
   100       Loss       15
   101       Loss       14
   102       Win       18
   103       Loss       17
   104       Loss       16
   105       Loss       15
   106       Loss       14
   107       Loss       13
   108       Loss       12
   109       Loss       11
   110       Loss       10
   111       Loss       9
   112       Loss       8
   113       Loss       7
   114       Loss       6
   115       Loss       5
   116       Loss       4
   117       Loss       3
   118       Loss       2
   119       Loss       1
   120       Win       5
   121       Loss       4
   122       Loss       3
   123       Win       7
   124       Loss       6
   125       Loss       5
   126       Loss       4
   127       Loss       3
   128       Loss       2
   129       Loss       1
   130       Win       5
   131       Win       9
   132       Loss       8
   133       Loss       7
   134       Loss       6
   135       Loss       5
   136       Loss       4
   137       Loss       3
   138       Loss       2
   139       Loss       1
   140       Loss       0
Sorry you're out of money
Would you like to play again?yes
What is your gambling budget?10
Number of rolls       Win or Loss   Current value of the pot
   0       Put       10
   1       Loss       9
   2       Win       13
   3       Loss       12
   4       Loss       11
   5       Loss       10
   6       Win       14
   7       Loss       13
   8       Loss       12
   9       Loss       11
   10       Loss       10
   11       Loss       9
   12       Win       13
   13       Loss       12
   14       Loss       11
   15       Loss       10
   16       Loss       9
   17       Win       13
   18       Loss       12
   19       Loss       11
   20       Loss       10
   21       Loss       9
   22       Loss       8
   23       Loss       7
   24       Loss       6
   25       Loss       5
   26       Loss       4
   27       Loss       3
   28       Loss       2
   29       Loss       1
   30       Win       5
   31       Loss       4
   32       Loss       3
   33       Loss       2
   34       Loss       1
   35       Loss       0
Sorry you're out of money
Would you like to play again?no
Goodbye
>>>

Program Screenshot


Related Solutions

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...
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...
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,...
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...
You make a carnival game, where the player rolls two fair dice (in a single roll)...
You make a carnival game, where the player rolls two fair dice (in a single roll) and attempts to roll doubles (meaning both dice show the same number). The player puts down a dollar to play the game. If the player loses, they lose their dollar. If the player wins, they win $3 (and do not lose their original dollar). Answer the following (5 pts total). If you are running the game, what is the expected value of how much...
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