In: Computer Science
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.
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