Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 26th, 2012, 08:04 PM
TheCluelessOne TheCluelessOne is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 TheCluelessOne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #2  
Old December 26th, 2012, 08:30 PM
Nyktos Nyktos is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 76 Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level) 
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 "!=".)

Reply With Quote
  #3  
Old December 26th, 2012, 08:42 PM
TheCluelessOne TheCluelessOne is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 TheCluelessOne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m
Reputation Power: 0
Reply

Well thats not the error though thanks.

its like this:

import randomxxx

Reply With Quote
  #4  
Old December 27th, 2012, 01:47 PM
StevenJM StevenJM is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 12 StevenJM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #5  
Old December 27th, 2012, 02:50 PM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 483 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 22 h 51 m 26 sec
Reputation Power: 63
Give us the full trace-back error message, it will help a lot.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

Reply With Quote
  #6  
Old December 27th, 2012, 03:57 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
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.

Reply With Quote
  #7  
Old December 27th, 2012, 05:50 PM
Jeff_Farkas Jeff_Farkas is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 1 Jeff_Farkas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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)?") 

Reply With Quote
  #8  
Old December 27th, 2012, 07:00 PM
Nyktos Nyktos is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 76 Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level) 
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.

Reply With Quote
  #9  
Old January 1st, 2013, 12:30 PM
JAHowe JAHowe is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 JAHowe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!

Reply With Quote
  #10  
Old January 7th, 2013, 04:06 PM
TheCluelessOne TheCluelessOne is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 TheCluelessOne User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #11  
Old January 7th, 2013, 04:21 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Help!!! Please!!!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap