Untitled

 avatar
unknown
plain_text
21 days ago
1.5 kB
3
Indexable
import random
import time

# Define the symbols for the slot machine
SYMBOLS = ["🍒", "🍋", "🍊", "🍇", "🔔", "💎", "7️⃣"]

# Function to spin the slot machine
def spin():
    return [random.choice(SYMBOLS) for _ in range(3)]

# Function to display the slot machine result
def display_result(reels):
    print("\nSpinning...\n")
    for i in range(3):  # Simulate spinning animation
        print(" | ".join(random.choices(SYMBOLS, k=3)), end="\r")
        time.sleep(0.5)
    print(" | ".join(reels))

# Function to check if the player won
def check_win(reels):
    if reels[0] == reels[1] == reels[2]:
        return True
    return False

# Main game loop
def slot_game():
    balance = 100  # Starting balance
    print("Welcome to the Python Slot Machine!")
    print(f"You start with ${balance}. Each spin costs $10.\n")

    while balance >= 10:
        input("Press Enter to spin (or type 'quit' to exit): ")
        if input().lower() == "quit":
            break

        balance -= 10  # Deduct spin cost
        reels = spin()
        display_result(reels)

        if check_win(reels):
            win_amount = 50  # Payout for a win
            balance += win_amount
            print(f"🎉 You won ${win_amount}! Your balance is now ${balance}.\n")
        else:
            print(f"😢 No win this time. Your balance is now ${balance}.\n")

    print("Game over! Thanks for playing.")
    print(f"Your final balance is ${balance}.")

# Run the game
if __name__ == "__main__":
    slot_game()
Editor is loading...
Leave a Comment