#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Help!!! Please!!!


    im trying to make this game. Its common and its my first project.

    Game:

    import random
    import time

    def displayIntro():
    print "You are in a land full of dragons."
    print "You are exploring and come upon two caves."
    print "In one cave, the dragon is friendly."
    print "In the other, the dragon will eat you alive"

    def chooseCave():
    cave = ""
    while cave != "1" and cave 1= "2":
    cave = raw_input("Which cave will you choose? (1 or 2)")

    return cave

    def checkCave(chosenCave):
    print "You approach the cave slowly..."
    time.sleep(3)
    print "It is murky and damp."
    time.sleep(3)
    print "From the shadows darts a dragon, mouth open wide..."
    time.sleep(3)

    friendlyCave = random.randint(1,2)

    if chosenCave == str(friendlyCave):
    print "The dragon calms down and gives you treasure. You are flabbergasted and return home."
    else:
    print "It eats you in one bite"

    playAgain = "yes"
    while playAgain == "yes" or playAgain == "y":
    displayIntro()

    caveNumber = chooseCave()

    checkCave(caveNumber)

    playAgain = raw_input("Do you want to play again? (yes or no)?




    it says "SyntaxError: multiple statements found while compiling a single statement."

    What do I do?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    114
    Rep Power
    3
    You really should put your code in code tags, which will preserve the indentation -- very important in Python.

    In this case I'll help since the answer did jump out at me in a quick glance at it. This line is likely the problem:
    Originally Posted by TheCluelessOne
    while cave != "1" and cave 1= "2":
    (Specifically that "1=" which I assume should be a "!=".)
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Reply


    Well thats not the error though thanks.

    its like this:

    import randomxxx
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0
    It's hard to tell what exactly is wrong with your code without proper tabbing.

    One thing I noticed is that you assign playAgain to "yes" and then immediately after have a while loop if playAgain is set to "yes" or "y". Because of this, your user input at the end of the code will never be used.
  8. #5
  9. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    610
    Rep Power
    65
    Give us the full trace-back error message, it will help a lot.
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    The problem Nyktos found certainly is a problem with your code. Another is your unclosed string and right parenthesis, which could be merely a forum copying error since it's at the very end of your program. If you're using python3 there are more problems.

    playAgain = raw_input("Do you want to play again? (yes or no)?


    (remainder of post removed)
    Last edited by b49P23TIvg; December 27th, 2012 at 03:59 PM. Reason: yuck. removed working program.
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0
    I cleaned up the code a bit.. and the import works fine in 2.5.3. HTH a bit.
    Here is the current error:
    NameError: name 'chosenCave' is not defined

    Code:
    import random
    import time
    
    def displayIntro():
        print "You are in a land full of dragons."
        print "You are exploring and come upon two caves."
        print "In one cave, the dragon is friendly."
        print "In the other, the dragon will eat you alive"
    
    def chooseCave():
        cave = ""
        while cave != "1" and cave != "2":
            cave = raw_input("Which cave will you choose? (1 or 2)")
        return cave
    
    def checkCave(chosenCave):
        print "You approach the cave slowly..."
        time.sleep(3)
        print "It is murky and damp."
        time.sleep(3)
        print "From the shadows darts a dragon, mouth open wide..."
        time.sleep(3)
    
    friendlyCave = random.randint(1,2)
    
    if chosenCave == str(friendlyCave):
        print "The dragon calms down and gives you treasure. You are flabbergasted and return home."
    else:
        print "It eats you in one bite"
    
    playAgain = "yes"
    while playAgain == "yes" or playAgain == "y":
        displayIntro()
    
    caveNumber = chooseCave()
    
    checkCave(caveNumber)
    
    playAgain = raw_input("Do you want to play again? (yes or no)?")
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    114
    Rep Power
    3
    The error there seems pretty self-explanatory...you reference the name "chosenCave" (specifically, in the first if-statement) but never defined anything by that name.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    Agreed. You defined "ChooseCave" but not "ChosenCave", to be specific. I've had the same problem before myself. Good luck!
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Error


    After the first statement:
    import random

    there is a red highlight saying "SyntaxError: multiple statements found while compiling a single statement"

    Help?
  20. #11
  21. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,854
    Rep Power
    481
    please post the 8 lines of code with "import random" in the middle. For example:

    Code:
    import random
    import time
    
    def displayIntro():
        print "You are in a land full of dragons."
        print "You are exploring and come upon two caves."
        print "In one cave, the dragon is friendly."
        print "In the other, the dragon will eat you alive"
    
    def chooseCave():
        cave = ""
        while cave != "1" and cave != "2":
            # etceteras
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo