저는 현재 약간의 바위, 종이, 가위 게임을 파이썬으로 코딩하고 있습니다. 그러나 문제가있는 것으로 보입니다. 게임은 코드가 약간 어둡더라도 작동하지만 프로그램에서 오류를 만든 플레이어에게이를 알리려고했습니다. 테스트 한 결과 무작위로 플레이어에게 오류를 알립니다. 그들은 아직 ~하지 못했다. 여기 내 문제는 코드 블록입니다, 그것은 전체 게임이 아닙니다.파이썬의 바위, 종이 가위 게임에 문제가 있습니다.
def game(self):
print "This is rock, paper, scissors!"
rps = ('rock', 'paper', 'scissors')
comp1 = raw_input("Rock, paper or scissors?\n> ")
comp2 = random.choice(rps)
if comp1 == 'rock' and comp2 == 'scissors' or comp1 == 'scissors' and comp2 == 'paper' or comp1 == 'paper' and comp2 == 'rock':
print "You won! The computer chose %s" % comp2
return "game"
elif comp1 == 'rock' and comp2 == 'rock':
print "In a stalemate, there are no winners, only losers :)\nThe computer also chose %s" % comp2
return "game"
elif comp1 == 'scissors' and comp2 == 'scissors':
print "In a stalemate, there are no winners, only losers :)\nThe computer also chose %s" % comp2
return "game"
elif comp1 == 'paper' and comp2 == 'paper':
print "In a stalemate, there are no winners, only losers :)\nThe computer also chose %s" % comp2
return "game"
elif comp1 != 'rock' or 'scissors' or 'paper':
print "Try choosing between rock, paper and scissors next time. It might help.
return "game"
else:
print "The computer %s. You have failed. Problem?" % comp2
return "game"
휴대 전화에서는 comp1을 소문자로 변환 해보세요. 교착 상태에 대해 comp1 == comp2로 논리를 단순화 할 수도 있습니다. – billinkc
복사 한 항목에 유효하지 않은 문자열 리터럴이 있기 때문에 실제 코드를 복사하지 않았습니다. –
왜 항상 "게임"이라는 문자열을 반환합니까, 그건 이상하게 보입니다 ... 아마 당신의 문제와 관련이 없습니다. –