그래서 내가 가지고있는 문제는 숫자를 더하려고 할 때 내 카운터가 계속 재설정되는 것입니다. 카운터 부분을 함수로 만드는 방법을 생각해 봤지만 숫자가 없습니다.가위 가위 반환 문제
winP1=0
winP2=0
tie=0
ans = input('Would you like to play ROCK, PAPER, SCISSORS?: ')
while ans == 'y':
p1c = input('Player 1 enter either R,P, or S: ') #p1c stands for "player 1 choice"
p2c = input('Player 2 enter either R,P, or S: ')
ans = input('Would you like to play again: ')
def game(p1c,p2c):
if p1c == p2c: #if its a tie we are going to add to the Tie variable
return 0
elif p1c == 'R' and p2c == 'P': #We will only set the Player 1 wins because
return 1 #player 2 wins can be set as else
elif p1c == 'P' and p2c == 'S':
return 1
elif p1c == 'S' and p2c == 'R':
return 1
else:
return -1
result = game(p1c,p2c)
if result == -1:
winP2 += 1
if result == 0:
tie += 1
else:
winP1 +=1
print('Player 1 won {} times. \nPlayer 2 won {} times. \nThere were {} ties.'.format(winP1,winP2,tie))
프로그램에서 while 루프가 영원히 계속됩니다. – aIKid
@alKid 아니오, 사용자 입력에 따라 while 루프의 마지막 줄에서 'ans'가 변경됩니다. –
오 예. 신경 쓰지 마. – aIKid