Question

In: Computer Science

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 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

                              1                                 Put                                   $10

                    2                                           Win                                  $14

                    3                                           Loss                                 $11

                              4

                              ##                              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, as well as 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

'''
Python version: 2.7
Python program to simulate the game of lucky sevens and
determine how many rolls it takes to empty the pot and the value of maximum pot during the game
'''
import random

# function to roll 2 die and return the result of sum of those die
def rollDie():
   return(random.randint(1,6) + random.randint(1,6))

# function to input and return the pot amount  
def pot_input():
   pot = int(raw_input('Enter the money in the pot : $')) # input of initial pot
      
   # validate the pot amount and re-prompt until valid
   while pot <= 0:
       print('Value of pot must be atleast 1')
       pot = int(raw_input('Enter the money in the pot : $')) # input of initial pot  
   return pot  
  
def main():
   while True: # loop that continues till the user wants
      
       pot = pot_input()
          
       rolls = 0
       maxPot = pot
       print('%20s %20s %s'%('Number of rolls','Win or Loss','Current value of the pot'))
       # loop that continues till the pot is non-empty
       while pot > 0:
           rolls = rolls + 1
           result = rollDie()
           # check the result
           if result == 7:
               pot = pot + 4
               print('%20d %20s %10s' %(rolls,'Win','$'+str(pot)))
           else:
               pot = pot - 1
               print('%20d %20s %10s' %(rolls,'Loss','$'+str(pot)))
           if pot > maxPot: #check for maxPot
               maxPot = pot
       #print the result
       print('Took %d rolls to empty the pot' %(rolls))
       print('Maximum pot : $%d' %(maxPot))
       cont = raw_input('Do you want to continue ? (y/n) ')
      
       if cont.lower() == 'n':
           break

#call the main function
if __name__ == "__main__":
   main()          

#end of program  

Code Screenshot:

Output:


Related Solutions

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...
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...
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...
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?
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,...
PROGRAMMING IN C-DICE GAME Q1. A player rolls two dice at the same time. Each die...
PROGRAMMING IN C-DICE GAME Q1. A player rolls two dice at the same time. Each die has six faces, which contain 1, 2, 3, 4, 5 and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. (i) If the sum is 2 or 10 on the first throw, the player wins. (ii) If the sum is 3, 7 or 12 on the first throw, the player loses. (iii)...
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...
In the game of craps, a player (known as the shooter) rolls two fair six-sided dice....
In the game of craps, a player (known as the shooter) rolls two fair six-sided dice. The shooter immediately loses if the sum of the dice is 2, 3, or 12 and immediately wins if the sum of the dice is 7 or 11 on the first roll. If the sum is anything else (4, 5, 6, 8, 9, or 10), that number becomes the point and the shooter rolls again. The shooter now wins by rolling that same point...
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...
A game works as follows: each player rolls one dice (let's call it ''n''). After both...
A game works as follows: each player rolls one dice (let's call it ''n''). After both players have made the first roll, they have the choice to leave or not. If a player exits, he automatically looses; if not, he rolls a second time (let's call this second roll "m'') and receives nm points . The player with the most points wins, in case of a tie no one wins. a) Give the fundamental space of the two throws. b)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT