2017-11-18 24 views
0

私は岩、紙、はさみを作っています。ロックペーパーはさみがループに詰まった

3勝または敗北の後、私はwhileループを離れることを望むが、それは動作し続ける。

################## 
# import modules # 
################## 

from random import randint 

# Declaration of variables # 

pcCounter, counter = 0, 0 
choice = "" 
pc = 0 

################ 
# Main program # 
################ 
print("Welcome to Dags Rock,Paper,Scissors") 
print("We will be playing a best out of 5") 
choice = input("Select rock, paper or scissors") 

while counter != 3 or pcCounter != 3: 
    if choice == "rock" or choice == "Rock": 
     pc = randint(1,3) 
     if pc == 1: 
      print("You have tied") 
      choice = input("Enter either rock, paper or scissors") 
     elif pc == 2: 
      print("You have lost, Paper beats rock") 
      pcCounter += 1 
      choice = input("Enter either rock, paper or scissors") 
     else: 
      print("You have won, rock beats scissors") 
      counter += 1 
      choice = input("Enter either rock, paper or scissors") 
    elif choice == "paper" or choice == "Paper": 
     pc = randint(1,3) 
     if pc == 1: 
      print("You have won, paper beats rock") 
      counter += 1 
      choice = input("Enter either rock, paper or scissors") 
     elif pc == 2: 
      print("You have tied") 
      choice = input("Enter either rock, paper or scissors") 
     else: 
      print("You have lost, scissors beats paper") 
      pcCounter += 1 
      choice = input("Enter either rock, paper or scissors") 
    else: 
     pc = randint(1,3) 
     if pc == 1: 
      print("You have lost, rock beats scissors") 
      pcCounter += 1 
      choice = input("Enter either rock, paper or scissors") 
     elif pc == 2: 
      print("You have won, scissors beats paper") 
      Counter += 1 
      choice = input("Enter either rock, paper or scissors") 
     else: 
      print("You have tied") 
      choice = input("Enter either rock, paper or scissors") 
#Checks if you won or lost    
if counter == 3: 
    print("Congratz you won :)") 
else: 
    print("Darn you lost :(")enter code here 

答えて

2

whileテストは正しくありません。変更:?あなたはどちらのカウンターがあなたの他の条件3.

+0

問題だったうん、おかげでトン、私は推測するだけで初心者のミス:Shivinによって指摘された追加的なバグがあることをD –

+0

注:一つの場所ではあなたではなく+ = '1'カウンターを持っています'counter + = 1'より。大文字小文字が重要なので、うまくいかない。 –

0

なぜ資本金はカウンタ変数が「C」である場合にのみ、ループを続けたい

while counter != 3 and pcCounter != 3: 

:へ

while counter != 3 or pcCounter != 3: 

カウンターではないはずですか?

else: 
     pc = randint(1,3) 
     if pc == 1: 
      print("You have lost, rock beats scissors") 
      pcCounter += 1 
      choice = input("Enter either rock, paper or scissors") 
     elif pc == 2: 
      print("You have won, scissors beats paper") 
      Counter += 1 
      choice = input("Enter either rock, paper or scissors") 
     else: 
      print("You have tied") 
      choice = input("Enter either rock, paper or scissors") 
+0

それは問題の根ではないが、それは良いキャッチだった、ありがとう、トン:) –

関連する問題