Ich programmiere einen Spielautomat für die Schule und kann nicht die Maschine erneut ausführen, sobald es fertig ist. Ich bin relativ neu und möchte ein ehrliches Feedback. Wie kann ich mein Programm erneut ausführen lassen? Dies ist der Code, mit dem ich das versuche. Ich habe meinen Code so geändert, dass er so aussieht.Erstellen eines Spielautomaten für die Schule
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)
Verwandte: [? Wie kann ich wieder laufen Code in Python] (http://stackoverflow.com/q/11459102/1014587) – Mast
Sie würden in der Regel Ihre Hauptfunktion oder gleichwertig innerhalb der Lauf While-Schleife und ausbrechen, wenn Sie es nicht neu starten möchten. Ohne zu wissen, wie der Rest Ihres Programms geschrieben ist, ist es schwer mehr zu sagen. Ich hoffe, du hast eine Hauptroutine, die du anrufst, um dein Programm zu starten, sonst wird es schwierig. – mata
Wenn Sie neu in der Programmierung sind, sieht dieser Code sehr nett aus :) – lelloman