Websites
The script simulates a simplified version of the game roulette, in which you can only place color bets (red or black) and straight bets (any number between and including 1-36). If you win a color bet, you get two times the amount of money you bet, since there are two color options. If you win a straight bet, you get 36 times the amount of money you bet, since there are 36 numerical options. Each player begins with $1000 and they can choose between No Zero roulette (36 total pockets, 36 possible winning pockets), French/Single Zero roulette (37 total pockets, 36 possible winning pockets), or American/Double Zero roulette (38 total pockets, 36 possible winning pockets). It serves as a simple and quick game to help fight boredom.
import numpy as np
import os
import sys
import argparse
#Options for color bets
=["R","B"]
colors
#Help message
if __name__ == "__main__":
= argparse.ArgumentParser(description="This is a simplified version of standard roulette. You can only place straight bets and color bets. Follow the prompts and enjoy!")
parser= parser.parse_args()
args
#Clears screen (purely aesthetics)
def wipescreen():
if sys.platform=="darwin" or sys.platform=="linux" or sys.platform=="linux2":
"clear")
os.system(elif sys.platform=="win32":
"cls")
os.system(
#No Zero roulette wheel spin (best odds: 36 pockets, 36 possible winning pockets)
def NoZero(bet):
if bet in np.arange(1,37):
=np.random.randint(37)
pocketelif bet in colors:
=colors[np.random.randint(2)]
pocketreturn pocket
#French roulette wheel spin (second best/second worst odds: 37 pockets, 36 possible winning pockets)
def French(bet):
if bet in np.arange(1,37):
=np.random.randint(38)
pocketif pocket==37:
=0
pocketelif bet in colors:
=np.random.randint(38)
pockif pock in np.arange(1,37,2):
="R"
pocketelif pock in np.arange(2,37,2):
="B"
pocketelse:
=0
pocketreturn pocket
#American roulette wheel spin (worst odds, 38 pockets, 36 possible winning pockets)
def American(bet):
if bet in np.arange(1,37):
=np.random.randint(39)
pocketif pocket==37:
=0
pocketelif pocket==38:
=0.0
pocketelif bet in colors:
=np.random.randint(38)
pockif pock in np.arange(1,37,2):
="R"
pocketelif pock in np.arange(2,37,2):
="B"
pocketelif pock==0:
=0
pocketelse:
=0.0
pocketreturn pocket
#One complete round
def spin(total):
wipescreen()print("Total: $"+str(total))
=0
d=0
w=0
f=0
z=int(input("Enter 1 for No Zero Roulette, 2 for French Roulette (Single Zero), and 3 for American Roulette (Double Zero). "))
rtypewhile d!=1:
=int(input("Now enter 1 to place a color bet (red or black) and 2 to place a straight bet (any integer from 1 to 36). "))
betkindif betkind==1:
while f!=1:
=input("Please enter R for red and B for black. ")
betif bet=="R" or bet=="B":
=f+1
felse:
print("Error: unknown input. Please try again.")
=d+1
delif betkind==2:
while z!=1:
=int(input("Please enter an integer from 1 to 36. "))
betif bet in np.arange(1,37):
=z+1
zelse:
print("Error: unknown input. Please try again.")
=d+1
delse:
print("Error: unknown input. Please try again.")
while w!=1:
=float(input("How much money would you like to bet? $"))
betamountif betamount>total:
print("You can't bet more than you have! Please try an amount less than "+str(total))
elif betamount<=0:
print("Error: invalid entry. Please try again.")
else:
=w+1
w=total-betamount
totalprint("Total: $"+str(total))
if rtype==1:
=NoZero(bet)
result
elif rtype==2:
=French(bet)
result
elif rtype==3:
=American(bet)
result
print("You bet on "+str(bet)+" and the result was "+str(result))
if bet==result:
if type(bet)==str:
=total+(betamount*2)
totalif type(bet)==int:
=total+(betamount*36)
totalprint("Great job! Your new total is: $"+str(total))
else:
print("Better luck next time!")
return total
#As soon as "python SimplifiedRoulette.py" is entered, clear the screen for game
wipescreen()
#Main game code
=input("Hi! Would you like to play roulette? [y/n] ")
initiateif initiate=="y":
=spin(1000)
total=0
bwhile b!=1:
=input("Would you like to play again? [y/n] ")
yesornoif yesorno=="y":
wipescreen()if total<=0:
print("Sorry, looks like you ran out of money. Better luck next time!")
sys.exit()else:
=spin(total)
totalelif yesorno=="n":
=b+1
bprint("Okay, have a great day!")
sys.exit()elif initiate=="n":
print("Okay, have a great day!")
sys.exit()