我正在开发一个程序,要求用户选择两个洞穴之一进入。用户可以选择洞穴 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)
谢谢您的帮助。