私は、ユーザーに2つの洞窟のうちの1つを選んで入るように求めるプログラムに取り組んでいます。ユーザーは洞窟1または洞窟2のいずれかを選択できます。その数が回答と比較されます(random.randint(1,2)によって生成されます)。ユーザーの選択が答えと等しい場合、彼は勝ちます。そうでなければ、彼は負けます。問題は、プログラムが勝利条件に分岐しないことです。ユーザーがどのような選択をしたとしても、彼は常に負けます。デバッグを試みましたが、caveAnswerとcaveChoiceの変数比較値が表示されません。
def gameCore (name):
print ('You stand before the entrances of two caves.')
print ('Choose a cave, either cave 1 or cave 2.')
print ( )
caveAnswer = random.randint (1,2)
caveChoice = input ('Enter either 1 or 2. ')
if caveAnswer == caveChoice: [# I suspect the problem occurs at this comparison]
print ('You enter the black mouth of the cave and...')
time.sleep (1)
print ( )
print ('You find a hill of shining gold coins!')
playAgain (name)
else:
print ('You enter the black mouth of the cave and...')
time.sleep(1)
print ( )
print ('A wave of yellow-orange fire envelopes you. You\'re toast.')
playAgain (name)
ご協力ありがとうございました。