From f2ae1e2f2636440d3309f118c061685ba42b17c1 Mon Sep 17 00:00:00 2001 From: Stephen Deaton Date: Tue, 25 Jun 2024 18:08:05 -0400 Subject: [PATCH] random rows and columns are Fed up --- PyGame/practice/textslot.py | 97 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 PyGame/practice/textslot.py diff --git a/PyGame/practice/textslot.py b/PyGame/practice/textslot.py new file mode 100644 index 0000000..2067882 --- /dev/null +++ b/PyGame/practice/textslot.py @@ -0,0 +1,97 @@ +import random + + +MAX_LINES = 3 +MAX_BET = 100 +MIN_BET = 1 +ROWS = 3 +COLS = 3 + +symbol_count = { + "A": 2, + "B": 4, + "C": 6, + "D": 8 +} + +def get_slot_machine_spin(rows, cols, symbol): + all_symbols = [] + for symbol, symbol_count in symbol.items(): #this is so as it picks from the list it gets the values and the index + for _ in range(symbol_count): # underscore ???? + all_symbols.append(symbol) + columns = [] + for _ in range(cols): + column = [] + current_symbols = all_symbols[:] + for _ in range(rows): + value = random.choice(current_symbols) + current_symbols.remove(value) + column.append(value) + + columns.append(column) + + return columns + +def print_slotmachine(columns): + for row in range(len(columns[0])): + for i, column in enumerate(columns): + if i != len(columns) - 1: + print(column[row], "|") + else: + print(column[row],) + +def deposit() -> int: + amount = 0 + while amount == 0: + response = input("What would you like to depsoit? $") + if response.isdigit(): + amount = int(response) + if amount == 0: + print(" Error: Amount must be greater than zero") + else: + print(" Error: Please enter a number") + return amount + +def get_number_of_lines() -> int: + lines = 0 + while lines < 1 or lines > MAX_LINES: + response = input("Enter the number of lines to bet on (1-" + str(MAX_LINES) + ")? ") + if response.isdigit(): + lines = int(response) + if lines < 1 or lines > MAX_LINES: + print(" Error: Enter a valid number of lines.") + else: + print(" Error: Please enter a number") + return lines + +def get_bet() -> int: + bet = 0 + while bet < MIN_BET or bet > MAX_BET: + amount = input("What would you like to Bet on each line? $") + if amount.isdigit(): + bet = int(amount) + if bet < MIN_BET or bet > MAX_BET: + print(f" Error: Amount must be between ${MIN_BET} - ${MAX_BET}.") + else: + print(" Error: Please enter a number") + return bet + +def main(): + balance = deposit() + lines = get_number_of_lines() + while True: + bet = get_bet() + total_bet = bet * lines + if total_bet > balance: + print(f" Error: You do not have enough to bet that amount, curent balance is: ${balance} ") + else: + break + total_bet = bet * lines + print(f"You are betting ${bet} on {lines} lines. Total bet is equal to: ${total_bet} ") + + slots = get_slot_machine_spin(ROWS, COLS, symbol_count) + print_slotmachine(slots) + + + +main() \ No newline at end of file