2016-08-29 2 views
1

학교용 슬롯 머신을 프로그래밍 중이며 완료되면 다시 실행할 수 없습니다. 나는 비교적 새롭고 정직한 피드백을 원합니다. 내 프로그램을 다시 실행하려면 어떻게해야합니까? 이것은 내가 이것을하려고하는 코드입니다. 방금이 코드를 수정했습니다.학교용 슬롯 머신 만들기

import random 
import sys 


print "Hi there user, welcome to the amazing poker machine simulator." 
print "Your opening account has in it $1000." 
print "To win a jackpot, three leprachauns must be in a row." 
print "Enter yes or no when prompted to finish or continue the program." 

balance = 1000 
balance == int(balance) 
winnings = 0 
winnings == int(winnings) 

Symbols = ["Leprachaun", "Goldbar", "Pyramid", "Blackcat"] 

# Subroutines: Checking the Bet input and amount 
def betcheck(betamount): 
    if betamount.isdigit() == True: 
     betamount == int(betamount) 
     rightbet = True 
    else: 
     rightbet = False 
     print "Please enter a whole number, no decimals and a bet on or below the balance." 
    return rightbet 

# Limiting the bet 
def betlimit(betamount): 
    if betamount > balance == False: 
     goodlimit = False 
     print "That bet is too high!" 
    else: 
     goodlimit = True 
    return goodlimit 

# Checking the 'Ask' input to play the 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 is an incorrect input, please type an appropriate answer in." 
    return rightanswerinput 

# Printing and sorting symbols. 
def spinning(reels): 
    global balance 
    if reelone == "Leprachaun" and reeltwo == "Leprachaun" and reelthree == "Leprachaun": 
     winnings = int(betamount) + int(balance) * 1000 
     print "You won the jackpot! Congragulations! This is how much your account contains $", winnings 
    elif reelone == "Goldbar" and reeltwo == "Goldbar" and reelthree == "Goldbar": 
     winnings = int(betamount) + int(balance) * 500 
     print "You won a considerable return! Awesome! Your balance and wins are $", winnings 
    elif reelone == "Pyramid" and reeltwo == "Pyramid" and reelthree == "Pyramid": 
     winnings = int(betamount) + int(balance) * 250 
     print "You won a good return! Its a conspiracy! This is all of your money total $", winnings 
    elif reelone == "Blackcat" and reeltwo == "Blackcat" and reelthree == "Blackcat": 
     winnings = int(balance) - int(betamount) 
     print "Unfortunately you didn't win anything, bad luck! You rewards are $", winnings 
    else: 
     winnings = int(balance) - int(betamount) 
     print "Bad luck! Maybe next time you'll win! Your remaining cash is $", winnings 
     print winnings 
    return reels 

# If you have no money 
def rebalance(balance):   
    while balance == 0 == True and startagain == True: 
     unbalance = True 
     balance = 1000 
     print "You ran out of money, here is $1000" 
    else: 
     unbalance = False 
     print "You still have money." 
     return unbalance 

# Leads to Bet input check. 
Validbet = False 
while Validbet == False: 
    betamount = raw_input("Please enter amount you wish to bet: ") 
    Validbet = betcheck(betamount) 

betamount == int(betamount) 

# Leads to 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 to Ask input check. (At the bottom due to program order) 
validask = False 
while validask == False: 
    answerinput = raw_input("Would you like to play again?: ") 
    validask = askinputcheck(answerinput) 

# Leads to 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 the game with", balance 
     break 
    else: 
     print "This is an incorrect input, please answer yes or no." 


# Leads to rebalance 
if answerinput == "Yes" or answerinput == "yes" or answerinput == "y" and balance == 0: 
    balance = rebalance(balance) 
+0

관련 : [? 어떻게 파이썬에서 내가 다시 실행 코드을 (http://stackoverflow.com/q/11459102/1014587) – Mast

+0

당신은 일반적으로 주요 기능을 실행하거나 내에서 동등한 것 while 루프를 실행하고 다시 시작하지 않으려면 중단하십시오. 나머지 프로그램이 어떻게 쓰여졌는지 알지 못하면 더 많은 것을 말하기가 어렵습니다. 나는 당신이 당신의 프로그램을 시작하기 위해 당신이 부르는 메인 루틴을 가지기를 바란다. 그렇지 않으면 어려울 것이다. – mata

+0

이 코드를 프로그래밍하는 것이 처음이라면 매우 멋지게 보입니다. – lelloman

답변

0

일부 여분의 시간을 보내고, 당신의 코드를 수정했습니다.
제공된 코드는 작은 코딩 및 논리적 오류로 가득합니다. diff 명령을 원래 코드와 아래 코드 사이에서 실행하면 많은 차이점이 있으며 버그가없는 것이 보장되지 않습니다.
동료 학생을 기용 할 계획이 없기를 바랍니다. rebalance 루틴은 미래의 상어의 뒤틀림 작업입니다. ;)

import random 

print "Hi there user, welcome to the amazing poker machine simulator." 
print "Your opening account has in it $1000." 
print "To win a jackpot, three leprachauns must be in a row." 
print "Enter yes or no when prompted to finish or continue the program." 

balance = 1000 


Symbols = ["Leprachaun", "Goldbar", "Pyramid", "Blackcat"] 

# Subroutines: Checking the Bet input and amount 
def betcheck(betamount): 
    if betamount.isdigit() == True: 
     betamount == int(betamount) 
     rightbet = True 
    else: 
     rightbet = False 
     print "Please enter a whole number, no decimals and a bet on or below the balance." 
    return rightbet 

# Limiting the bet 
def betlimit(betamount): 
    if betamount > balance: 
     goodlimit = balance 
     print "That bet is too high! - bet adjusted to ", goodlimit 
    else: 
     goodlimit = betamount 
    return goodlimit 

# Checking the 'Ask' input to play the machine. 
def askinputcheck(answerinput): 
    if answerinput.lower().startswith('y') or answerinput.lower().startswith("n"): 
     rightanswerinput = True 
    else: 
     rightanswerinput = False 
     print "This is an incorrect input, please type an appropriate answer in." 
    return rightanswerinput 

# Printing and sorting symbols. 
def spinning(reels, betamount): 
    reelone, reeltwo, reelthree = reels[0], reels[1], reels[2] 
    global balance 
    winnings = 0 
    if reelone == "Leprachaun" and reeltwo == "Leprachaun" and reelthree == "Leprachaun": 
     winnings = int(betamount) * 10 + int(balance) 
     print "You won the jackpot! Congragulations! This is how much your account contains $", winnings 
    elif reelone == "Goldbar" and reeltwo == "Goldbar" and reelthree == "Goldbar": 
     winnings = int(betamount) *5 + int(balance) 
     print "You won a considerable return! Awesome! Your balance and wins are $", winnings 
    elif reelone == "Pyramid" and reeltwo == "Pyramid" and reelthree == "Pyramid": 
     winnings = int(betamount) *2 + int(balance) 
     print "You won a good return! Its a conspiracy! This is all of your money total $", winnings 
    elif reelone == "Blackcat" and reeltwo == "Blackcat" and reelthree == "Blackcat": 
     winnings = int(balance) - int(betamount) 
     print "Unfortunately you didn't win anything, bad luck! You rewards are $", winnings 
    else: 
     winnings = int(balance) - int(betamount) 
     print "Bad luck! Maybe next time you'll win! Your remaining cash is $", winnings 
    balance = winnings 
    return reels 

# If you have no money 
def rebalance(startagain): 
    global balance 
    if balance < 1 and startagain == True: 
     unbalance = True 
     balance = 1000 
     print "You ran out of money, here is $1000" 
    else: 
     unbalance = False 
     print "You still have money." 
    return unbalance 

# Leads to Bet input check. 
def my_mainloop(): 
    global balance 
    while True: 
     Validbet = False 
     while Validbet == False: 
      betamount = raw_input("Please enter amount you wish to bet: ") 
      Validbet = betcheck(betamount) 

     betamount = int(betamount) 
     # Leads to 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 to Ask input check. (At the bottom due to program order) 
     validask = False 
     while validask == False: 
      answerinput = raw_input("\nWould you like to 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 the game with", balance 
      break 
     else: 
      print "This is an incorrect input, please answer yes or no." 

      # Leads to rebalance 
     if answerinput.lower().startswith("y") and balance < 1: 
      rebalance(startagain) 

if __name__ == "__main__": 
    my_mainloop()