I’m working on a program that asks the user to pick one of two caves to enter. User may pick either cave 1 or cave 2. That number is compared to the answer (generated by random.randint (1,2)). If the user’s choice is equal to the answer, he wins; else, he loses. The issue is that the program never branches to the win condition. No matter what choice user makes, he always loses. I’ve tried debugging but I cannot see the variable comparison values between caveAnswer and 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)
Thank you for your help.
You should also make it so that it’ll try again if it’s not an int.