1- import random
1+ import random
22MAX_LINES = 3
33MAX_BET = 100
44MIN_BET = 1
2020 "D" : 2
2121}
2222
23+
2324def check_winnings (columns , lines , bet , values ):
2425 winnings = 0
2526 winning_lines = []
@@ -28,14 +29,15 @@ def check_winnings(columns, lines, bet, values):
2829 for column in columns :
2930 symbol_to_check = column [line ]
3031 if symbol != symbol_to_check :
31- break
32+ break
3233 else :
33- winnings += values [symbol ]* bet
34+ winnings += values [symbol ] * bet
3435 winning_lines .append (line + 1 )
3536
3637 return winnings , winning_lines
3738
38- def get_slot_machine_spin (rows ,cols , symbols ):
39+
40+ def get_slot_machine_spin (rows , cols , symbols ):
3941 all_symbols = []
4042 for symbol , symbol_count in symbols .items ():
4143 for _ in range (symbol_count ):
@@ -54,16 +56,18 @@ def get_slot_machine_spin(rows,cols, symbols):
5456
5557 return columns
5658
59+
5760def print_slot_machine (columns ):
5861 for row in range (len (columns [0 ])):
5962 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 = " | " )
6265 else :
6366 print (column [row ], end = "" )
6467
6568 print ()
6669
70+
6771def deposit ():
6872 while True :
6973 amount = input ("What would you like to deposit? $" )
@@ -78,19 +82,22 @@ def deposit():
7882
7983 return amount
8084
85+
8186def 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 ():
8591 lines = int (lines )
86- if 1 <= lines <= MAX_LINES :
92+ if 1 <= lines <= MAX_LINES :
8793 break
8894 else :
8995 print ("enter a valid number of lines." )
90- else :
96+ else :
9197 print ("please enter a number. " )
9298
93- return lines
99+ return lines
100+
94101
95102def get_bet ():
96103 while True :
@@ -105,28 +112,32 @@ def get_bet():
105112 print ("please enter a number. " )
106113
107114 return amount
108-
115+
116+
109117def spin (balance ):
110118 lines = get_number_of_lines ()
111119 while True :
112- bet = get_bet ()
113- total_bet = bet * lines
120+ bet = get_bet ()
121+ total_bet = bet * lines
114122
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 } ." )
117126
118- else :
119- break
127+ else :
128+ break
120129
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 } " )
122132
123133 slots = get_slot_machine_spin (ROWS , COLS , symbol_count )
124134 print_slot_machine (slots )
125135 winnings , winning_lines = check_winnings (slots , lines , bet , symbol_value )
126136 print (f"You won ${ winnings } ." )
127137 print (f"You won on lines: " , * winning_lines )
128138 return winnings - total_bet
129-
139+
140+
130141def main ():
131142 balance = deposit ()
132143 while True :
@@ -138,4 +149,5 @@ def main():
138149
139150 print (f"You left with ${ balance } " )
140151
152+
141153main ()
0 commit comments