내 라운드를 추적하는 메소드를 생성하기 위해 튜플을 사용하도록 제안되었지만, 그런 일을 어떻게 수행 할 것인지 혼란 스럽습니다. Player의 오브젝트와 컴퓨터의 오브젝트와 각 라운드에서 누가 이겼는지 추적하고 싶습니다. 그러나 프로그램의 디자인으로 인해 while 루프를 10 회 반복하지 않고 추적 할 필요없이 어떻게 달성 할 수 있는지 이해할 수 없습니다 기존 튜플 내부에 새로운 요소를 추가 할 수 없습니다,하지만 당신은 목록으로 그렇게 할 수 있다는 것을 의미 승자무한 루프와 관련된 튜플
import random
Rounds = []
Player_Score = 0
Computer_Score = 0
while Player_Score < 5 and Computer_Score < 5:
Player_object = input("Would you like to choose R, P, or S?")
Computer_object = random.sample("RPS", 1)[0]
if Player_object == "R" or Player_object == "r":
if Computer_object == "R":
print("You have chosen " +Player_object+ " and the Computer chose " +str(Computer_object)+ ".You have tied with the Computer and neither of you have scored a point.")
elif Computer_object == "P":
Computer_Score += 1
print("You have chosen " +Player_object+ " and the Computer chose " +str(Computer_object)+ ". You have been beaten by the Computer and it has scored a point.")
else:
Player_Score += 1
print("You have chosen " +Player_object+ " and the Computer chose " +str(Computer_object)+ ".You have beaten the Computer and you have scored a point.")
if Player_object == "P" or Player_object == "p":
if str(Computer_object) == "R":
Player_Score += 1
print("You have chosen " +Player_object+ " and the Computer chose " +str(Computer_object)+ ".You have beaten the Computer and you have scored a point.")
elif str(Computer_object) == "P":
print("You have chosen " +Player_object+ " and the Computer chose " +str(Computer_object)+ ". You have tied with the Computer and neither of you have scored a point.")
else:
Computer_Score += 1
print("You have chosen " +Player_object+ " and the Computer chose " +str(Computer_object)+ ".You have been beaten by the Computer and it has scored a point.")
if Player_object == "S" or Player_object == "s":
if str(Computer_object) == "R":
print("You have chosen " +Player_object+ " and the Computer chose " +str(Computer_object)+ ".You have been beaten by the Computer and it has scored a point.")
elif str(Computer_object) == "P":
Computer_Score += 1
print("You have chosen " +Player_object+ " and the Computer chose " +str(Computer_object)+ ". You have beaten the Computer and you have scored a point.")
else:
Player_Score += 1
print("You have chosen " +Player_object+ " and the Computer chose " +str(Computer_object)+ ".You have tied with the Computer and neither of you have scored a point.")
if Computer_Score == 5 and Player_Score != 5:
print("The Computer has won!")
if Player_Score == 5 and Computer_Score != 5:
print("You have won and beaten the computer")
Rounds = Rounds.append((Player_object_set, Computer_object_set))
R = "Rock"
r = "Rock"
P = "Paper"
p = "Paper"
S = "Scissors"
s = "Scissors"
print(Rounds[0][0])
이 질문에 대한 질문이 없습니다. – thebjorn
@Joe, 좀 더 구체적으로 알려 주실 수 있습니까? –
기본적으로 묻는 것은 튜플을 사용하여 루프의 끝에서 많은 변수를 인쇄하는 방법입니다. 나는 인쇄하고 싶다. "라운드 X, 플레이어가 Y를 선택하고 컴퓨터가 Z를 선택했습니다." –