Jump to content
  • Advertisement
Sign in to follow this  
RLS0812

Python 3 Slot Machine

This topic is 2518 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here is a working beta of a slot machine I am working on. Eventuallly I will add a GUI to it.

# Python 3
# Slot Machine
# By : RLS0812
# Note: The Odds are a bit off of what they actually are.
import random
def Reels():
# [0]Winning Value, [1]Fruit, [2]Fruit, [3]Fruit
Ret_Val = [0," "," "," "]
# Spin those reels !
Reel_Spin = random.randrange(1,4,1),random.randrange(1,4,1),random.randrange(1,4,1)
# Reel 1
if Reel_Spin[0] == 1:
Ret_Val[0] += 1
Ret_Val[1] = "Banana"
if Reel_Spin[0] == 2:
Ret_Val[0] += 5
Ret_Val[1] = "Orange"
if Reel_Spin[0] == 3:
Ret_Val[0] += 20
Ret_Val[1] = "Cherry"
# Reel 2
if Reel_Spin[1] == 1:
Ret_Val[0] += 1
Ret_Val[2] = "Banana"
if Reel_Spin[1] == 2:
Ret_Val[0] += 5
Ret_Val[2] = "Orange"
if Reel_Spin[1] == 3:
Ret_Val[0] += 20
Ret_Val[2] = "Cherry"
# Reel 3
if Reel_Spin[2] == 1:
Ret_Val[0] += 1
Ret_Val[3] = "Banana"
if Reel_Spin[2] == 2:
Ret_Val[0] += 5
Ret_Val[3] = "Orange"
if Reel_Spin[2] == 3:
Ret_Val[0] += 20
Ret_Val[3] = "Cherry"
return Ret_Val
# Starting Values
Player_Money = 1000
Jack_Pot = 100
Run = True
while Run == True:
Bet = 0
# Reset if player goes broke
if Player_Money < 1:
input("You have no more money. Here is $ 1000 \nPress Enter \n")
Player_Money = 1000
Jack_Pot = 100
# User input
Bet_Line = input(" Place Your Bet ! \n Jackpot $ " + str(Jack_Pot) + "\n Money $ " + str(Player_Money) + "\n Q = quit \n")
if Bet_Line == "q" or Bet_Line == "Q":
Run = False
break
try:
Bet = int(Bet_Line)
except:
print("Error: '" + Bet_Line + "' is not a number !")
pass
# Not enough money
if Bet > Player_Money:
print("Sory, you only have $",Player_Money, "\n")
# Lets play !
elif Bet <= Player_Money and Bet != 0:
Jack_Pot += (int(Bet*.15))
Player_Money -= Bet
Is_Winner = Reels()
I_W = Is_Winner[0]
Fruits = Is_Winner[1] + " - " + Is_Winner[2] + " - " + Is_Winner[3]
# Match 3 - 1 in 9 chance
if I_W == 3 or I_W == 15 or I_W == 60:
print(Fruits + "\n" + "You Won $ " + str(Bet*4) + " !!! \n")
Player_Money += (Bet*4)
# Jackpot 1 in 450 chance of winnning
JP1 = random.randrange(1,51,1)
JP2 = random.randrange(1,51,1)
if JP1 == JP2:
print ("You Won The Jackpot !!!\nHere is your $ " + str(Jack_Pot) + " prize! \n")
Jack_Pot = 100
elif JP1 != JP2:
print ("You did not win the Jackpot this time. \nPlease try again ! \n")
# Match 2 - 1 in 4.5 chance
elif I_W == 7 or I_W == 22 or I_W == 11 or I_W == 30 or I_W == 41 or I_W == 45:
print(Fruits + "\n" + "You Won $ " + str(int(Bet*.5)) + " !!! \n")
Player_Money += (int(Bet*.5))
# No win
else:
print(Fruits + "\nPlease try again. \n")
#The End
print("- Program Terminated -")


Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!