[Python] Slot Machine generator in python , two functions are'nt working ( def...

Discussão em 'Python' iniciado por Stack, Abril 19, 2025.

  1. Stack

    Stack Membro Participativo

    import random
    MIN_LINES = 1
    MAX_LINES = 3
    MAX_BET = 100
    MIN_BET = 1

    ROW = 3
    COL = 3

    symbol_count = {
    "A":2,
    "B":4,
    "C":6,
    "D": 8,
    }

    def get_slot_machine_spin(rows,cols,symbols):
    all_symbols = []
    for symbol , symbol_count in symbols.items():
    for _ in range(symbol_count):
    all_symbols.append(symbol)
    columns = [[],[],[]]
    for _ in range(cols):
    current_symbols = all_symbols[:]
    for _ in range(rows):
    value = random.choice(current_symbols)
    current_symbols.remove(value)
    columns.append(value)
    columns.append(columns)
    return columns

    def print_slot_machine(colmuns):
    for row in range(len(colmuns[0])):
    for i , colmun in enumerate(colmuns):
    if i != len(colmun) - 1:
    print(colmun[row], end="|")
    else:
    print(colmun[row], end="")
    print()
    def deposit():
    amount = input("inter the amount of deposit you'd like to add ")
    if amount.isdigit():
    amount = int(amount)
    while amount > 0:
    break
    else: print("amount must be more than 0")
    else: print("Please enter a number ")
    return amount

    def get_number_of_lines():
    lines = input("inter the amount of lines you'd like to add ")
    if lines.isdigit():
    lines = int(lines)
    while MIN_LINES <= lines <= MAX_LINES:
    break
    else: print("amount must be between 1~3")
    else: print("Please enter a number ")
    return lines


    def get_bet():
    while True:
    amount = input("Inter the amount of deposit you'd like to bet \n")
    if amount.isdigit():
    amount = int(amount)
    while MIN_BET <= amount <= MAX_BET:
    break
    else:
    print(f"The amount must be between ${MIN_BET}and ${MAX_BET}\n ")
    else:
    print("Please enter a number ")
    return amount

    def main():
    balance = deposit()
    lines = get_number_of_lines()
    while True:
    bet = get_bet()
    total_bet = bet *lines
    if total_bet> balance:
    print(f"you dont have enough to bet on that amount , your current balance is {balance}")
    else:
    break
    print(f"you're betting {bet},on {lines} lines . total bet is = ${total_bet}")
    slots = get_slot_machine_spin(ROW, COL,symbol_count)
    print_slot_machine(slots)
    main()


    I tried changing the two lines in many different ways but it didnt work plz help

    slots = get_slot_machine_spin(ROW, COL,symbol_count)
    print_slot_machine(slots)


    i got this code from a utube video called (Learn Python With This ONE Project!) i wrote the same code as but when he excute the code it shows him the Slot machine results ( abcd ) while am not getting it , i hope my question was clear ,,, all i want is to make the functions work and show the results of the random choices

    Continue reading...

Compartilhe esta Página