The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Help!!! Please!!!
Discuss Help!!! Please!!! in the Python Programming forum on Dev Shed. Help!!! Please!!! Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 26th, 2012, 08:04 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 7 m
Reputation 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?
|

December 26th, 2012, 08:30 PM
|
|
Contributing User
|
|
Join Date: Dec 2012
Posts: 76
  
Time spent in forums: 1 Day 3 h 26 m 18 sec
Reputation Power: 2
|
|
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:
Quote: | Originally Posted by TheCluelessOne while cave != "1" and cave 1= "2": |
(Specifically that "1=" which I assume should be a "!=".)
|

December 26th, 2012, 08:42 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 7 m
Reputation Power: 0
|
|
|
Reply
Well thats not the error though thanks.
its like this:
import randomxxx
|

December 27th, 2012, 01:47 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 12
Time spent in forums: 3 h 51 m 27 sec
Reputation 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.
|

December 27th, 2012, 02:50 PM
|
 |
Contributing User
|
|
|
|
|
Give us the full trace-back error message, it will help a lot.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
|

December 27th, 2012, 03:57 PM
|
 |
Contributing User
|
|
|
|
|
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)
__________________
[code] Code tags[/code] are essential for python code!
Last edited by b49P23TIvg : December 27th, 2012 at 03:59 PM.
Reason: yuck. removed working program.
|

December 27th, 2012, 05:50 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 1
Time spent in forums: 53 m 49 sec
Reputation 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)?")
|

December 27th, 2012, 07:00 PM
|
|
Contributing User
|
|
Join Date: Dec 2012
Posts: 76
  
Time spent in forums: 1 Day 3 h 26 m 18 sec
Reputation Power: 2
|
|
|
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.
|

January 1st, 2013, 12:30 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 1 h 12 m 43 sec
Reputation Power: 0
|
|
Agreed. You defined "ChooseCave" but not "ChosenCave", to be specific.  I've had the same problem before myself. Good luck!
|

January 7th, 2013, 04:06 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 3
Time spent in forums: 7 m
Reputation 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?
|

January 7th, 2013, 04:21 PM
|
 |
Contributing User
|
|
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|