-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslot_machine.py
More file actions
36 lines (30 loc) Β· 1.47 KB
/
slot_machine.py
File metadata and controls
36 lines (30 loc) Β· 1.47 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
#
# A python program that simulates a slot machine.
# Having the following items... 'π',' π', 'π', '7οΈβ£'.
import random
# Creates the function
def play():
# the initial list
symbols = ['π',' π', 'π', '7οΈβ£']
# This boolean basically instructs python to keep running the program indefinetly, therefore
# the need for a 'break' is needed within per user input within a conditional statement.
while True:
results = random.choices(symbols, k=3) #prints 3 random results
pretty_results = '|'.join(results) #puts the results b/w pipes
print(pretty_results) # printsd the results for the user.
if results == ['7οΈβ£', '7οΈβ£', '7οΈβ£']: # The main checker for desired results
print("Jackpot! π°")
break #What will ultimately break the infinite loop we created with the boolean.
else:
print("Will roll again!")
user_cont = input("Wanna play again?: ") # Variable whether to end or continue
print("Press 'Y' to continue or 'N' to not play again.")
if user_cont == 'N': # Ends the program for good with a message
print("Thanks for playing.")
elif user_cont == 'Y':
play() # Restarts the program from the top
else: # Ends the program for good with a message incase of any weird input.
print("Weird input, terminating program.")
play()
# Resources:
#https://stackoverflow.com/questions/62992294/how-to-print-out-the-list-items-horizontally