-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslotMachine.py
86 lines (63 loc) · 2.01 KB
/
slotMachine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Python Slot Machine
import random
def spin_row():
symbols = ["🍒", "🍉", "🍋", "🔔", "⭐"]
weights = [200, 300, 500, 400, 100]
return [random.choices(symbols, weights=weights, k=1)[0] for _ in range(3)]
def print_row(row):
print("*************")
print(" | ".join(row))
print("*************")
def get_payout(row):
if all(symbol == "🍒" for symbol in row):
return 5
elif all(symbol == "🍉" for symbol in row):
return 10
elif all(symbol == "🍋" for symbol in row):
return 20
elif all(symbol == "🔔" for symbol in row):
return 40
elif all(symbol == "⭐" for symbol in row):
return 100
return 0
def main():
balance = 100
print("***************************")
print(" Welcome to Python Slots ")
print(" Symbols: 🍒 🍉 🍋 🔔 ⭐ ")
print("***************************")
while balance > 0:
print(f"Current balance: ${balance}")
bet = input("Place your bet amount (or 'q' to quit): ")
if bet.lower() == 'q':
print(f"Thanks for playing! You're leaving with ${balance}")
break
if not bet.isdigit():
print("Please enter a valid number.")
continue
bet = int(bet)
if bet > balance:
print("Insufficient funds.")
continue
if bet <= 0:
print("Bet must be greater than 0.")
continue
balance -= bet
row = spin_row()
print("Spinning ...\n")
print_row(row)
payout_multiplier = get_payout(row)
if payout_multiplier > 0:
winnings = bet * payout_multiplier
balance += winnings
print(f"Congratulations! You won ${winnings}!")
else:
print("Sorry, no win this time.")
if balance <= 0:
print("Game over. You've run out of money.")
print("*********************************************")
print(f"Game over! Your final balance id ${balance}.")
print("Goodbye!")
print("*********************************************")
if __name__ == "__main__":
main()