-
Notifications
You must be signed in to change notification settings - Fork 1
/
slot_machine.py
60 lines (49 loc) · 2.02 KB
/
slot_machine.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
from ascii_art import slot_machine_logo
import random
symbols = ["🍒", "🍋", "🍉"]
def play_slot_machine():
while True:
print(slot_machine_logo)
tokens = int(input("Enter Tokens: "))
while tokens > 0:
print(f"You have ", tokens, " tokens \n")
try:
action = input("Enter '1' to spin or '0' to cash out: ")
if action == '0':
print("Thanks for playing!\n")
print("Your cash out is", tokens)
break
elif action == '1':
bet = int(input("Bet amount: "))
else:
print("Invalid input! Please enter '1' to spin or '0' to cash out.")
continue
except ValueError:
print("Please enter a whole number of tokens!")
continue
if bet > tokens:
print("Not enough tokens.")
else:
tokens -= bet
sq_one = random.choice(symbols)
sq_two = random.choice(symbols)
sq_three = random.choice(symbols)
print()
print("|", random.choice(symbols), "|", random.choice(symbols), "|", random.choice(symbols), "|")
print("----------------")
print("|", sq_one, "|", sq_two, "|", sq_three, "|")
print("----------------")
print("|", random.choice(symbols), "|", random.choice(symbols), "|", random.choice(symbols), "|")
print("----------------")
if sq_one == sq_two and sq_two == sq_three:
amount_won = bet * 2
print("You won", amount_won, "tokens!")
tokens += amount_won
else:
print("You lost this time")
if tokens == 0:
print("\nYou are out of tokens.")
print("Thank you for playing Slots!")
print("")
print()
break