python - Creating a slot machine for school -
i'm programming slot machine school , cannot machine re-run once finished. relatively new , honest feedback. how can program re-run? code i'm trying with. i've modified code this.
import random import sys print "hi there user, welcome amazing poker machine simulator." print "your opening account has in $1000." print "to win jackpot, 3 leprachauns must in row." print "enter yes or no when prompted finish or continue program." balance = 1000 balance == int(balance) winnings = 0 winnings == int(winnings) symbols = ["leprachaun", "goldbar", "pyramid", "blackcat"] # subroutines: checking bet input , amount def betcheck(betamount): if betamount.isdigit() == true: betamount == int(betamount) rightbet = true else: rightbet = false print "please enter whole number, no decimals , bet on or below balance." return rightbet # limiting bet def betlimit(betamount): if betamount > balance == false: goodlimit = false print "that bet high!" else: goodlimit = true return goodlimit # checking 'ask' input play machine. def askinputcheck(answerinput): if answerinput == "yes" or answerinput == "yes" or answerinput == "y" or answerinput == "no" or answerinput == "no" or answerinput == "n": rightanswerinput = true else: rightanswerinput = false print "this incorrect input, please type appropriate answer in." return rightanswerinput # printing , sorting symbols. def spinning(reels): global balance if reelone == "leprachaun" , reeltwo == "leprachaun" , reelthree == "leprachaun": winnings = int(betamount) + int(balance) * 1000 print "you won jackpot! congragulations! how account contains $", winnings elif reelone == "goldbar" , reeltwo == "goldbar" , reelthree == "goldbar": winnings = int(betamount) + int(balance) * 500 print "you won considerable return! awesome! balance , wins $", winnings elif reelone == "pyramid" , reeltwo == "pyramid" , reelthree == "pyramid": winnings = int(betamount) + int(balance) * 250 print "you won return! conspiracy! of money total $", winnings elif reelone == "blackcat" , reeltwo == "blackcat" , reelthree == "blackcat": winnings = int(balance) - int(betamount) print "unfortunately didn't win anything, bad luck! rewards $", winnings else: winnings = int(balance) - int(betamount) print "bad luck! maybe next time you'll win! remaining cash $", winnings print winnings return reels # if have no money def rebalance(balance): while balance == 0 == true , startagain == true: unbalance = true balance = 1000 print "you ran out of money, here $1000" else: unbalance = false print "you still have money." return unbalance # leads bet input check. validbet = false while validbet == false: betamount = raw_input("please enter amount wish bet: ") validbet = betcheck(betamount) betamount == int(betamount) # leads betlimit appropriatelimit = betlimit(betamount) # randomsymbolgen + 3 reels reelone = random.sample(["leprachaun", "goldbar", "goldbar", "pyramid", "pyramid", "pyramid", "blackcat", "blackcat", "blackcat", "blackcat"],1) reeltwo = random.sample(["leprachaun", "goldbar", "goldbar", "pyramid", "pyramid", "pyramid", "blackcat", "blackcat", "blackcat", "blackcat"],1) reelthree = random.sample(["leprachaun", "goldbar", "goldbar", "pyramid", "pyramid", "pyramid", "blackcat", "blackcat", "blackcat", "blackcat"],1) reels = [reelone, reeltwo, reelthree] slotspin = spinning(reels) print reels # leads ask input check. (at bottom due program order) validask = false while validask == false: answerinput = raw_input("would play again?: ") validask = askinputcheck(answerinput) # leads restart startagain = false while startagain == false: startagain = answerinput while true: if answerinput == "yes" or answerinput == "yes" or answerinput == "y": startagain = true balance = int(winnings) + int(balance) print "you have $", balance pass elif answerinput == "no" or answerinput == "no" or answerinput == "n": startagain = false balance = winnings print "you ended game with", balance break else: print "this incorrect input, please answer yes or no." # leads rebalance if answerinput == "yes" or answerinput == "yes" or answerinput == "y" , balance == 0: balance = rebalance(balance)
having spare time, have modified code.
code supplied riddled small coding , logical errors. best running diff
command between original code , code below, see many differences , there no guarantee bug free either.
hope you're not planning on fleecing fellow pupils, rebalance
routine twisted work of future loan-shark. ;)
import random print "hi there user, welcome amazing poker machine simulator." print "your opening account has in $1000." print "to win jackpot, 3 leprachauns must in row." print "enter yes or no when prompted finish or continue program." balance = 1000 symbols = ["leprachaun", "goldbar", "pyramid", "blackcat"] # subroutines: checking bet input , amount def betcheck(betamount): if betamount.isdigit() == true: betamount == int(betamount) rightbet = true else: rightbet = false print "please enter whole number, no decimals , bet on or below balance." return rightbet # limiting bet def betlimit(betamount): if betamount > balance: goodlimit = balance print "that bet high! - bet adjusted ", goodlimit else: goodlimit = betamount return goodlimit # checking 'ask' input play machine. def askinputcheck(answerinput): if answerinput.lower().startswith('y') or answerinput.lower().startswith("n"): rightanswerinput = true else: rightanswerinput = false print "this incorrect input, please type appropriate answer in." return rightanswerinput # printing , sorting symbols. def spinning(reels, betamount): reelone, reeltwo, reelthree = reels[0], reels[1], reels[2] global balance winnings = 0 if reelone == "leprachaun" , reeltwo == "leprachaun" , reelthree == "leprachaun": winnings = int(betamount) * 10 + int(balance) print "you won jackpot! congragulations! how account contains $", winnings elif reelone == "goldbar" , reeltwo == "goldbar" , reelthree == "goldbar": winnings = int(betamount) *5 + int(balance) print "you won considerable return! awesome! balance , wins $", winnings elif reelone == "pyramid" , reeltwo == "pyramid" , reelthree == "pyramid": winnings = int(betamount) *2 + int(balance) print "you won return! conspiracy! of money total $", winnings elif reelone == "blackcat" , reeltwo == "blackcat" , reelthree == "blackcat": winnings = int(balance) - int(betamount) print "unfortunately didn't win anything, bad luck! rewards $", winnings else: winnings = int(balance) - int(betamount) print "bad luck! maybe next time you'll win! remaining cash $", winnings balance = winnings return reels # if have no money def rebalance(startagain): global balance if balance < 1 , startagain == true: unbalance = true balance = 1000 print "you ran out of money, here $1000" else: unbalance = false print "you still have money." return unbalance # leads bet input check. def my_mainloop(): global balance while true: validbet = false while validbet == false: betamount = raw_input("please enter amount wish bet: ") validbet = betcheck(betamount) betamount = int(betamount) # leads betlimit betamount = betlimit(betamount) # randomsymbolgen + 3 reels if betamount > 0: reelone = random.sample(["leprachaun", "goldbar", "goldbar", "pyramid", "pyramid", "pyramid", "blackcat", "blackcat", "blackcat", "blackcat"],1) reeltwo = random.sample(["leprachaun", "goldbar", "goldbar", "pyramid", "pyramid", "pyramid", "blackcat", "blackcat", "blackcat", "blackcat"],1) reelthree = random.sample(["leprachaun", "goldbar", "goldbar", "pyramid", "pyramid", "pyramid", "blackcat", "blackcat", "blackcat", "blackcat"],1) reels = [reelone, reeltwo, reelthree] print "\n",reels,"\n" slotspin = spinning(reels, betamount) # leads ask input check. (at bottom due program order) validask = false while validask == false: answerinput = raw_input("\nwould play again?: ") validask = askinputcheck(answerinput) if answerinput.lower().startswith("y"): startagain = true print "you have $", balance elif answerinput.lower().startswith("n"): startagain = false print "you ended game with", balance break else: print "this incorrect input, please answer yes or no." # leads rebalance if answerinput.lower().startswith("y") , balance < 1: rebalance(startagain) if __name__ == "__main__": my_mainloop()
Comments
Post a Comment