2017-11-21 16 views
-1

私はちょうどPythonでプログラミングすることを学び始めました。私は自分自身を鍛えるためにロックペーパー - はさみゲームを作ろうとします。whileループ引数が考慮されない

私は変数を作成し、無限ループ

で終了しないように引数を追加する必要がありますので、もしそれが私のcomputer_scoreを考慮していない、whileループ とコードの末尾に問題を抱えています
user_choice = "Rock" 
user_score = 0 
computer_score = 0 


def fight(user_choice): 
    if user_choice == "Rock": 
     scissor = 1 
     rock = 2 
     paper = 3 
     user_choice = rock 
     computer_choice = randint(1, 3) 
     print computer_choice 
     if user_choice == computer_choice: 
      print 'DRAW!' 
     elif user_choice > computer_choice: 
      print 'User win, consciousness can\'t be beaten, you win' 
      global user_score 
      user_score += 1 
     elif user_choice < computer_choice: 
      print 'Computer win, singularity has been reach' 
      global computer_score 
      computer_score += 1 


i = 0 
while (computer_score < 3 or i < 30): 
    fight(user_choice) 
    i = i + 1 
+4

'computer_score'が50で、' i'が15であるとします。その状況で 'computer_score <3またはi <30'が評価するものを考えてみましょう。 – Kevin

+0

コンピュータが勝ったときに 'prints 'しているので、選択したものに固有のものではないので、それらの' statement'のうちの1つをランダムに印刷することができます。 –

答えて

0

randint(1,3)は常に1を返す場合がありますので、コンピュータは決して勝てません。このようにして、whileループは無限に続きます。

+0

これは非常に起こりそうもなく、OPの問題を引き起こす原因でもありません。 @ケビンはすでに彼のコメントで問題を特定した。 –

関連する問題