Skip to content

Instantly share code, notes, and snippets.

@slapglif
Last active September 19, 2018 19:26
Show Gist options
  • Save slapglif/335c39c4807bd1d7d260b558d5aee06f to your computer and use it in GitHub Desktop.
Save slapglif/335c39c4807bd1d7d260b558d5aee06f to your computer and use it in GitHub Desktop.
import random
red = ["1","3","5","7","9","12","14","16","18","21","23","25","27","30","32","34","36"]
black = ["2","4","6","8","10","11","13","15","17","19","20","22","24","26","28","29","31","33","35"]
green = ["0"]
even = ["2","4","6","8","10","12","14","16","18","20","22","24","26","28","30","32","34","36"]
odd = ["1","3","5","7","9","11","13","15","17","19","21","23","25","27","29","31","33","35"]
def results():
result = []
result.append(str(random.randint(0, 36)))
if result[0] in red:
result.append('red')
if result[0] in black:
result.append('black')
if result[0] in even:
result.append('even')
if result[0] in odd:
result.append('odd')
if result[0] in green:
result.append('green')
return result
def bet_won(bet, bankroll, winnings):
bankroll[0] = bankroll[0] + float(bet) + float(winnings)
return bankroll[0]
def win_or_lose(bet, result, pick):
output = ""
print("Placing bet for: " + str(bet) + ", Current Bankroll: " + str(bankroll[0]))
bankroll[0] = bankroll[0] - float(bet)
if len(pick) > 1:
winnings = str(round(float(bet)*2.0, 2))
if result[0] in red and pick[1] in result[0]:
output = "Roll: " + result[0] + " red" + "\nYou won! Earnings: " + winnings
bet_won(bet, bankroll, winnings)
elif result[0] in black and pick[1] in result[0]:
output = "Roll: " + result[0] + " black" + "\nYou won! Earnings: " + winnings
bet_won(bet, bankroll, winnings)
elif result[0] in green and pick[1] in result[0]:
output = "Roll: " + result[0] + " green" + "\nYou won! Earnings: " + winnings
bet_won(bet, bankroll, winnings)
else:
output = "Result was: " + result[0] + " " + result[1] + "\nSorry, you lose!"
if len(pick) == 1:
winnings = str(round(float(bet)*1.0, 2))
if result[0] in red and pick[0] == "red":
output = "Roll: " + result[0] + " red" + "\nYou won! Earnings: " + winnings
bet_won(bet, bankroll, winnings)
elif result[0] in odd and pick[0] == "odd":
output = "Roll: " + result[0] + " odd" + "\nYou won! Earnings: " + winnings
bet_won(bet, bankroll, winnings)
elif result[0] in even and pick[0] == "even":
output = "Roll: " + result[0] + " even" + "\nYou won! Earnings: " + winnings
bet_won(bet, bankroll, winnings)
else:
output = "Result was: " + result[0] + " " + result[1] + "\nSorry, you lose!"
return output
def spin(user_input):
result = results()
pick = []
input_list = user_input.split()
try:
if len(input_list) > 2:
pick.append(str(input_list[1]))
pick.append(str(input_list[0]))
bet = str(input_list[2])
if bankroll[0] > 0 and float(bet) < bankroll[0] and float(bet) > 0:
if int(pick[0]) <= 36:
if pick[1] in "red,black,even,odd":
print(win_or_lose(bet, result, pick))
else:
print("You must pick: red, black, even, odd")
else:
print("Must pick a number between 0-36...")
else:
if int(bet) == 0:
print("You must bet more than 0")
else:
print("Insufficient Bankroll")
else:
pick.append(str(input_list[0]))
bet = str(input_list[1])
if bankroll[0] > 0 and float(bet) <= bankroll[0] and float(bet) > 0:
if pick[0] in "red,black,even,odd":
print(win_or_lose(bet, result, pick))
else:
print("You must pick: red, black, even, odd")
else:
if int(bet) == 0:
print("You must bet more than 0")
else:
print("Insufficient Bankroll")
except Exception as e:
print("Retry Bet\nSyntax is: red/black [number] [bet amount] or red/black [amount]"
"\nExample: red 13, black 10 1, odd 1")
# print(e)
selection()
return result
def selection():
choice = input("Current Bankroll: " + str(bankroll[0]) + "\n")
print(spin(choice))
if __name__ == "__main__":
print("Spin to win, You can choose:\n red [number], black [number], "
"even, odd, or red, black followed by your bet ammount\n Example: red 11 3, odd 5, red 10"
"\n Your starting bankroll: 100")
bankroll = [100]
selection()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment