Slot Machine Game

Slot Machine Game

Simple slot machine written in python. This project takes advantage of the Random library and also using dictionaries.

Here is a example of a dictionary it uses:

#Dictionary with the number count of each symbol
symbol_count = {
    "A": 2,
    "B": 4,
    "C": 6,
    "D": 8
}

#Dictionary with the value of each symbol 
symbol_value = {
    "A": 5,
    "B": 4,
    "C": 3,
    "D": 2
}

Once the distionaries were in place and all the variables were set I proceded to add my function.

Example of some of the functions:



#This function when called will check the output of the slot machince and calc your winnings
def chech_winnings(columns, lines, bet, values):
    winnings = 0
    winning_lines = []
    for line in range(lines):
        symbol = columns[0][line]
        for column in columns:
            symbol_to_check = column[line]
            if symbol != symbol_to_check:
                break
        else:
            winnings += values[symbol] * bet
            winning_lines.append(lines + 1)

    return winnings, winning_lines

#This function will ask the user to input a deposit and it saves this deposit for later calculations
def deposit():
    while True:
        amount = input("What would you like to deposit? $")
        if amount.isdigit():
            amount = int(amount)
            if amount > 0:
                break
            else:
                print("Amount must be greater than 0.")
        else:
            print("Please enter a number.")

    return amount

And finally once all the functions were made I began calling each one and asking for user imputs using once again another function 😅.

#This function initiates the initial funtions for the game and provides a option for the payer to bail out.
def main():
    balance = deposit()
    while True:
        print(f"Current balence is ${balance}")
        answer = input("Press enter to play (q to quit).")
        if answer == "q":
            break
        balance += spin(balance)

    print(f"You left with ${balance}")

And last but not least you run the main() function:

main()

Thank you for reading till the end! If you want you can check out all the code for this porject and much more at my GitLab