In: Computer Science
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.
Thanks for the question.
Below is the code you will be needing Let me know if you have any doubts or if you need anything to change.
Thank You !!
===========================================================================
import random
def get_dice_sum():
return random.randint(1, 6) + random.randint(1, 6)
def get_pot_money():
while True:
try:
money = int(input('Enter initial amount of money to put into the pot: '))
if money <= 0:
print('Error: Amount cannot be equal or less than 0')
else:
return money
except:
print('Error: Invalid number. Please enter a valid number')
def main():
money = get_pot_money()
print('{0:>15}{1:>15}{2:>30}'.format('Number of rolls', 'Win or Loss', 'Current value of pot'))
print('{0:>15}{1:>15}{2:>30}'.format(1, 'Put', '${}'.format(money)))
rolls = 1
while money != 0:
dice_sum = get_dice_sum()
rolls += 1
if dice_sum == 7:
money += 4
print('{0:>15}{1:>15}{2:>30}'.format(rolls, 'Win', '${}'.format(money)))
else:
money -= 1
print('{0:>15}{1:>15}{2:>30}'.format(rolls, 'Loss', '${}'.format(money)))
print('You lost your money after {} rolls of play.'.format(rolls))
main()
=============================================================================

