forked from JMBeattie-Personal/SlotMachine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlotMachine2.0
47 lines (38 loc) · 1.86 KB
/
SlotMachine2.0
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
print("Let's play some slots! But, be warned, one false spin could cost more than you care to wager...")
slotsPossible = ["bar","bar","bar","bar","bar","cherry","crown","crown","bar","bar","cherry","crown","skull"]
# adding in a starting cash amount so that we can add/subtract based on results of slot machine "spin"
cashAmount = 100
from random import *
def play():
slot1=choice(slotsPossible)
slot2=choice(slotsPossible)
slot3=choice(slotsPossible)
# using the global keyword so that it can use my cashAmount variable above
# if this isn't used, it throws an error, thinking that cashAmount hasn't been defined yet
global cashAmount
# this sets the default response output for when the outcome is NOT a winning combination
win = "Thanks for your money."
if (slot1==slot2==slot3=="cherry"):
win = "You win $1000"
cashAmount = cashAmount + 1000
elif (slot1==slot2==slot3=="crown"):
win = "You win $500"
cashAmount = cashAmount + 500
elif (slot1==slot2==slot3=="bar"):
win = "You win $50"
cashAmount = cashAmount + 50
elif (slot1==slot2==slot3=="skull"):
win = "That was a costly mistake..."
cashAmount = 0
return slot1+":"+slot2+":"+slot3+" "+win
# First see if they want to play
playAgain = input("Do you want to try? It only costs $10 to play...Remember: high risk, high reward.")
# then play until they don't type "yes"
# Info on while loops (used below): https://docs.python.org/3/reference/compound_stmts.html#while
while (playAgain in ("yes","Yes","YES","Y","y")):
cashAmount = cashAmount - 10
print(play())
print("You now have", cashAmount, "dollars remaining. Choose wisely.")
playAgain = input("Do you want to try again? Remember, high risk, high reward.")
# this statement runs when they don't type "yes"
print("Better luck next time!")