-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlotMachine.py
More file actions
96 lines (76 loc) · 2.36 KB
/
SlotMachine.py
File metadata and controls
96 lines (76 loc) · 2.36 KB
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
87
88
89
90
91
92
93
94
95
96
#A begineer slot machine program in python
import random
import time
def spin_row():
symbols = ['🍒','🍉','🍋','⭐','🔔']
results = []
for symbol in range(3):
results.append(random.choice(symbols))
return results
def print_row(row):
print("*************")
for i in range(3):
print(f"| {row[i]} | ", end='')
time.sleep(1)
print("\n*************")
def get_payout(row,bet):
if row[0] == row[1] == row[2]:
if row[0] == '🍒':
return bet * 3
elif row[0] == '🍉':
return bet * 4
elif row[0] == '🍋':
return bet * 5
elif row[0] == '🔔':
return bet * 10
elif row[0] == '⭐':
return bet * 20
elif row[0] == row[1] or row[1] == row[2]:
if row[0] == '🍒':
return bet * 1.2
elif row[0] == '🍉':
return bet * 1.4
elif row[0] == '🍋':
return bet * 1.5
elif row[0] == '🔔':
return bet * 2
elif row[0] == '⭐':
return bet * 3
else:
return 0
def main():
balance = 1000
print("************************************")
print("Welcome to Python Slot Machine")
print("Symbols: 🍒 🍉 🍋 ⭐ 🔔")
print("************************************")
while balance > 0:
print(f"Current Balance Rs.{balance}")
bet = input("Place your bets: ")
if not bet.isdigit():
print("Enter a valid Number: ")
continue
bet = int(bet)
if bet > balance:
print("Insufficient Balance")
continue
if bet <= 0:
print("Bet must be greater than zero.")
continue
balance -= bet
row = spin_row()
print("Spinning...\n")
time.sleep(2)
print_row(row)
payout = get_payout(row,bet)
if payout > 0:
print(f"You won Rs.{payout}")
else:
print("You Lost this round.")
balance += payout
play_again = input("Do you want to spin again(Y/N): ").upper()
if play_again != 'Y':
break
print(f"Game Over! Your final balance is Rs.{balance}")
if __name__ == '__main__':
main()