1
- import random
1
+ import random
2
2
MAX_LINES = 3
3
3
MAX_BET = 100
4
4
MIN_BET = 1
20
20
"D" : 2
21
21
}
22
22
23
+
23
24
def check_winnings (columns , lines , bet , values ):
24
25
winnings = 0
25
26
winning_lines = []
@@ -28,14 +29,15 @@ def check_winnings(columns, lines, bet, values):
28
29
for column in columns :
29
30
symbol_to_check = column [line ]
30
31
if symbol != symbol_to_check :
31
- break
32
+ break
32
33
else :
33
- winnings += values [symbol ]* bet
34
+ winnings += values [symbol ] * bet
34
35
winning_lines .append (line + 1 )
35
36
36
37
return winnings , winning_lines
37
38
38
- def get_slot_machine_spin (rows ,cols , symbols ):
39
+
40
+ def get_slot_machine_spin (rows , cols , symbols ):
39
41
all_symbols = []
40
42
for symbol , symbol_count in symbols .items ():
41
43
for _ in range (symbol_count ):
@@ -54,16 +56,18 @@ def get_slot_machine_spin(rows,cols, symbols):
54
56
55
57
return columns
56
58
59
+
57
60
def print_slot_machine (columns ):
58
61
for row in range (len (columns [0 ])):
59
62
for i , column in enumerate (columns ):
60
- if i != len (columns )- 1 :
61
- print (column [row ], end = " | " )
63
+ if i != len (columns )- 1 :
64
+ print (column [row ], end = " | " )
62
65
else :
63
66
print (column [row ], end = "" )
64
67
65
68
print ()
66
69
70
+
67
71
def deposit ():
68
72
while True :
69
73
amount = input ("What would you like to deposit? $" )
@@ -78,19 +82,22 @@ def deposit():
78
82
79
83
return amount
80
84
85
+
81
86
def get_number_of_lines ():
82
- while True :
83
- lines = input ("Enter the number of lines to bet on (1-" + str (MAX_LINES ) + ")? " )
84
- if lines .isdigit ():
87
+ while True :
88
+ lines = input (
89
+ "Enter the number of lines to bet on (1-" + str (MAX_LINES ) + ")? " )
90
+ if lines .isdigit ():
85
91
lines = int (lines )
86
- if 1 <= lines <= MAX_LINES :
92
+ if 1 <= lines <= MAX_LINES :
87
93
break
88
94
else :
89
95
print ("enter a valid number of lines." )
90
- else :
96
+ else :
91
97
print ("please enter a number. " )
92
98
93
- return lines
99
+ return lines
100
+
94
101
95
102
def get_bet ():
96
103
while True :
@@ -105,28 +112,32 @@ def get_bet():
105
112
print ("please enter a number. " )
106
113
107
114
return amount
108
-
115
+
116
+
109
117
def spin (balance ):
110
118
lines = get_number_of_lines ()
111
119
while True :
112
- bet = get_bet ()
113
- total_bet = bet * lines
120
+ bet = get_bet ()
121
+ total_bet = bet * lines
114
122
115
- if total_bet > balance :
116
- print (f"You do not have enough money to bet that amount, your current balance is: ${ balance } ." )
123
+ if total_bet > balance :
124
+ print (
125
+ f"You do not have enough money to bet that amount, your current balance is: ${ balance } ." )
117
126
118
- else :
119
- break
127
+ else :
128
+ break
120
129
121
- print (f"You are betting ${ bet } on { lines } lines. Total be is equal to: ${ total_bet } " )
130
+ print (
131
+ f"You are betting ${ bet } on { lines } lines. Total be is equal to: ${ total_bet } " )
122
132
123
133
slots = get_slot_machine_spin (ROWS , COLS , symbol_count )
124
134
print_slot_machine (slots )
125
135
winnings , winning_lines = check_winnings (slots , lines , bet , symbol_value )
126
136
print (f"You won ${ winnings } ." )
127
137
print (f"You won on lines: " , * winning_lines )
128
138
return winnings - total_bet
129
-
139
+
140
+
130
141
def main ():
131
142
balance = deposit ()
132
143
while True :
@@ -138,4 +149,5 @@ def main():
138
149
139
150
print (f"You left with ${ balance } " )
140
151
152
+
141
153
main ()
0 commit comments