私は以下のコードを持っていますが、playing = falseのときにplayer2がサイコロを動かせるようにフローを制御しません。誰もがエラーを見つけることができますか?基本的に、それは決して得られない:RollTwoDiceP2と私は理由を理解できない。ブール制御フロー変数が正しく実装されていません
注:私は、playerturns()関数に戻るときに、今回はRollTwoDiceP2(Player2 turn sub)に行くことを期待して、RollTwoDiceP1でfalse(Boolean変数)をfalseに設定しようとしました。 。それは
def callmatrix(player1,player2, n):
print("*************LOADING GAME******************")
print("Welcome:", player1,"and", player2)
for i in matrix(n):
print(i)
playing = True
playerturns(player1,player2,playing)
def playerturns(player1,player2,playing):
print(" - - - - - - - - - - ")
print("Press Enter to contnue")
#playing = True
while(playing):
roll=input()
if roll=="r" or "R":
RollTwoDiceP1(player1,player2)
else:
RollTwoDiceP2(player1,player2)
def RollTwoDiceP1(player1,player2):
turn=input("Player 1, it's your turn to roll the dice: Press r to roll:>>>")
#create two variables here and assign them random numbers
die1=random.randint(1,6)
die2=random.randint(1,6)
#add the two die numbers together
roll=die1+die2
#when you are printing an integer, you need to cast it into a string before you printit
print("Player1: You rolled a:", die1, "and a", die2, "which give you a:", roll)
playing = False
playerturns(player1,player2,playing)
def RollTwoDiceP2(player1,player2):
turn=input("Player 2, it's your turn to roll the dice: Press r to roll:>>>")
#create two variables here and assign them random numbers
die1=random.randint(1,6)
die2=random.randint(1,6)
#add the two die numbers together
roll=die1+die2
print("Player2: You rolled a:", die1, "and a", die2, "which give you a:", roll)
playing = True
playerturns(player1,player2,7,playing)
出力は動作しません:
Continually asks Player 1 to Roll. Prints the result of Player 1s roll (repeat)
これは論理エラーなので、指定された問題の複製ではありません。
@TidB - いいえ、私は何かをする方法を尋ねるのではなく、私のプログラムのロジックを分析し、提案を与えました –