I have no idea


#1

Hello I don't know were else to post this I did not want to start a new account on a different websites to ask just one question. I've been learning Python 3 and I just cant figure out why this program wont run. I've gone through it with the debugger but I get nothing. It would be really cool to find out what I did wrong with my code cause I want to learn.

import random
import time

def display():
print('You are in a land of dragons and in front of you is ')
print('two caves one cave has a dragon that will share ')
print('two caves one cave has a dragon that will share ')
print('the knowledge of lifting in the other is a dragon that will kill you on sight')
print()

def chooseCave():
cave = ' '
while cave != '1' and cave != '2':
print('Brave traveler which cave do you choose? 1 or 2?')
cave = input()
return cave

def checkCave(chooseCave):
print('You approach teh cave...')
time.sleep(2)
print('It is dark and spooky')
time.sleep(2)
print('The dragon jumps out in front of you and opens his mouth and...')
print()
time.sleep(2)

friendlyCave=random.randint(1,2)

if chooseCave == str(friendlyCave):
    print('Gives you the secret to fitness...Its rely not that cool go read a book')
else:
    print('He eats you up from the foot to your head...Man that sucks!')

playAgain = 'Yes'

while playAgain == 'yes' or playAgain =='y':
display()
caveNumber=chooseCave()
checkCave(caveNumber)
print('Would you like to play again User? (Yes or No)')
playAgain = input()


#2

You should write 'yes' instead of 'Yes'

playAgain = 'yes'

because:

You check for non-capital-letter yes and that's why it won't start :smiley:


#3

I'm just going to list some things as I see them:


  • your code:
    print('Brave traveler which cave do you choose? 1 or 2?')
    cave = input()

  • try this:
    cave = raw_input("Brave traveler which cave do you choose? 1 or 2?")


  • you defined 'playAgain' without asking the user...

  • I am just going to rewrite a bit of your code and paste it for you to take a look at here:

while True: 
    display()
    ''' caveNumber = chooseCave() would not work '''
    caveNumber = cave
    checkCave(caveNumber)
    ''' you have to write it like this for it to understand that is needs to handle a yes or no answer '''
    playAgain = raw_input("Would you like to play again? Enter [yes or no]: ")
    if playAgain.lower()[0] == "y":
        continue
    elif playAgain.lower()[0] == "n":
        break
    else:
        ''' This is to handle if they type something random like "nipples", for example... '''
        print "Invalid input"
        time.sleep(2)
        print "Exiting..."
        break

This above code needs to be placed where you wrote this:

Hope I could help! :slightly_smiling:


#5

Thank you it works now. Computers man they can be tricky.


#6

You're welcome ^^
Computers are more dumb than you think, you have to tell them literally everthing :wink:


#7

This post was flagged by the community and is temporarily hidden.