0

私のブラックジャック ゲームは動作しますが、ゲームの最後に再びプレイするオプションがあるようにするにはどうすればループできますか? どうもありがとう!ループが必要です。乾杯

import random
endGame = (False)


dealer = random.randrange(2,20)
player = random.randrange(2,20)

print ("\n*********LETS PLAY BLACK JACK***********\n")
print ("Your starting total is "+str(player))



while endGame==(False):
    action =input("What do you want to do? stick[s] or twist[t]? ")
    if action == ("s"):
        print ("Your total is "+str(player))
        print ("Dealer's total is "+str(dealer))
        if player > dealer:
            print ("*You win!*")
        else:
            print ("Dealer wins")
            endGame = True

    if action == ("t"):
        newCard = random.randrange(1,10)
        print ("You drew "+str(newCard))
        player = player + newCard
        if player > 21:
            print ("*Bust! You lose*")
            endGame = True
        else:
            print ("Your total is now "+str(player))
            if dealer < 17:
                newDealer = random.randrange(1,10)
                dealer = dealer + newDealer

                if dealer > 21:
                    print ("*Dealer has bust! You win!")
                    endGame = True
4

2 に答える 2

0

whileこれを別のループでラップするか、2 つの別個の関数を使用できます。

while True:
    endgame = False
    while not endgame:
        #game actions
    play_again = raw_input("Play again y or n?")
    if play_again == 'n':
        break

または、これを異なる関数に分割することもできます:

def play_again():
    play_option = raw_input("Play again y or n?")
    if play_option == 'y': game_play()


def game_play():
    endgame = False
    while not endgame:
        #game_actions
    play_again()
于 2013-11-11T14:54:48.227 に答える