943,847 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 514
  • Python RSS
Jun 15th, 2009
0

"X not defined"?

Expand Post »
Python Syntax (Toggle Plain Text)
  1. print "INSERT QUIZ INTRO"
  2. choices1();
  3.  
  4. def choices1():
  5. print "The SNES Star Fox games ran off of/was used to advertise what advancement?"
  6. print "1: 32 Bit color"
  7. print "2: Argonaut's Super FX Chip"
  8. print "3: Voice-like sound effects"
  9. print "4: Higher Frame rates"
  10. 001();

There's code past this but I imagine this is where it matters. When I run this, it says "NameError: name 'choices1' is not defined"

What can I do to fix this?
Last edited by pupspark; Jun 15th, 2009 at 7:17 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pupspark is offline Offline
4 posts
since Jun 2009
Jun 15th, 2009
0

Re: "X not defined"?

Click to Expand / Collapse  Quote originally posted by pupspark ...
Python Syntax (Toggle Plain Text)
  1. print "INSERT QUIZ INTRO"
  2. choices1();
  3.  
  4. def choices1():
  5. print "The SNES Star Fox games ran off of/was used to advertise what advancement?"
  6. print "1: 32 Bit color"
  7. print "2: Argonaut's Super FX Chip"
  8. print "3: Voice-like sound effects"
  9. print "4: Higher Frame rates"
  10. 001();

There's code past this but I imagine this is where it matters. When I run this, it says "choices1 not defined"

What can I do to fix this?

I think you should define the quote before u call it..

[QUOTE=pupspark;891264]
Python Syntax (Toggle Plain Text)
  1.  
  2. def choices1():
  3. print "The SNES Star Fox games ran off of/was used to advertise what advancement?"
  4. print "1: 32 Bit color"
  5. print "2: Argonaut's Super FX Chip"
  6. print "3: Voice-like sound effects"
  7. print "4: Higher Frame rates"
  8. 001();
  9.  
  10. print "INSERT QUIZ INTRO"
  11. choices1();
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
xav.vijay is offline Offline
52 posts
since Aug 2005
Jun 15th, 2009
0

Re: "X not defined"?

Click to Expand / Collapse  Quote originally posted by pupspark ...
Python Syntax (Toggle Plain Text)
  1. print "INSERT QUIZ INTRO"
  2. choices1()
  3.  
  4. def choices1():
  5. print "The SNES Star Fox games ran off of/was used to advertise what advancement?"
  6. print "1: 32 Bit color"
  7. print "2: Argonaut's Super FX Chip"
  8. print "3: Voice-like sound effects"
  9. print "4: Higher Frame rates"
  10. 001();

There's code past this but I imagine this is where it matters. When I run this, it says "choices1 not defined"

What can I do to fix this?
When you call choices1, it isn't yet defined. The solution is pretty obvious.

python Syntax (Toggle Plain Text)
  1. def choices1():
  2. print "The SNES Star Fox games ran off of/was used to advertise what advancement?"
  3. print "1: 32 Bit color"
  4. print "2: Argonaut's Super FX Chip"
  5. print "3: Voice-like sound effects"
  6. print "4: Higher Frame rates"
  7. # 001(); This is guaranteed to raise an error on you.
  8.  
  9. print "INSERT QUIZ INTRO"
  10. choices1()

Btw, Python doesn't need semi-colons as line delimiters. Go read a tutorial.
Last edited by scru; Jun 15th, 2009 at 7:22 pm.
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007
Jun 15th, 2009
0

Re: "X not defined"?

Thanks! It worked! I didn't know it needed to be previously defined. Thank you!

While you're at it, could you tell me why line 7 is invalid syntax?

Python Syntax (Toggle Plain Text)
  1. def loss():
  2. print "Game Over. Try again!"
  3. "--------"
  4. begin();
  5. def input2():
  6. choice = input('Enter choice number:')
  7. if (choice == 1)
  8. loss();
  9. if (choice == 2)
  10. loss();
  11. if (choice == 3)
  12. choices3();
  13. if (choice == 4)
  14. loss();
  15. print "--------"
  16.  
  17. def choices2():
  18. print "What was the name of the Sharpclaw leader?"
  19. print "Andross"
  20. print "Sauria"
  21. print "General Scales"
  22. print "President Scales"
  23. "--------"
  24. def input1():
  25. choice = input('Enter choice number:');
  26. if (choice == 1):
  27. loss();
  28. if (choice == 2):
  29. choices2();
  30. if (choice == 3):
  31. loss();
  32. if (choice == 4):
  33. loss();
  34. "--------"
  35.  
  36. def choices1():
  37. print "The SNES Star Fox games ran off of/was used to advertise what advancement?"
  38. print "1: 32 Bit color"
  39. print "2: Argonaut's Super FX Chip"
  40. print "3: Voice-like sound effects"
  41. print "4: Higher Frame rates"
  42. input1();
  43. "--------"
  44.  
  45. print "Welcome to Pizearke's Star Fox quiz! Simply type the number of the correct choice after where it asks you to enter the choice number and press enter to play. There are ten questions. The quiz will restart if you get one wrong. Don't worry though, it's pretty easy. Try to get all the way through!"
  46. print"--------"
  47. choices1();
Last edited by pupspark; Jun 15th, 2009 at 7:42 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pupspark is offline Offline
4 posts
since Jun 2009
Jun 15th, 2009
0

Re: "X not defined"?

Seems like you are transitioning from c++/c to python. ( BTW when you have an if statement, you don't have to have parenthesizes around your expression). When you call a function, there is no need to put a semicolon next to it. Taking it away should resolve the problem.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
besktrap is offline Offline
58 posts
since Jul 2008
Jun 15th, 2009
0

Re: "X not defined"?

Click to Expand / Collapse  Quote originally posted by besktrap ...
Seems like you are transitioning from c++/c to python. ( BTW when you have an if statement, you don't have to have parenthesizes around your expression). When you call a function, there is no need to put a semicolon next to it. Taking it away should resolve the problem.
Actually, I'm new to programming all together. Thanks, though!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pupspark is offline Offline
4 posts
since Jun 2009
Jun 16th, 2009
0

Re: "X not defined"?

Click to Expand / Collapse  Quote originally posted by pupspark ...
Actually, I'm new to programming all together. Thanks, though!
From where are you learning your python then? I'd like to destroy whatever the source may be...
Reputation Points: 355
Solved Threads: 292
Veteran Poster
jlm699 is offline Offline
1,102 posts
since Jul 2008
Jun 16th, 2009
-1

Re: "X not defined"?

>While you're at it, could you tell me why line 7 is invalid syntax?
Line 7 would have made sense if you had followed the proper syntax of the code tags:
[code=python]
// the code which goes here will have
// line numbers at left side
[/code]

Anyways, it turns out that you don't even know the proper syntax of if statement. If was not a bad thing if you were migrating from another language, but the fact is that you are starting programming for the first time.

Anyways, this is the proper syntax:
python Syntax (Toggle Plain Text)
  1. if <condition> : #notice the colon
  2. //do something when
  3. //the condition is true

>I'd like to destroy whatever the source may be...
I would be glad to help you.

PS: Please follow a definitive tutorial or book to study python. The good part is: that there are enormous resources available for you to learn and most of them are free. You could start learning by the official Python Tutorial or perhaps "How to think Like a Computer Scientist" is also a valuable resource
Reputation Points: 1486
Solved Threads: 140
Practically a Posting Shark
siddhant3s is offline Offline
816 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Separating Numeric Lines from Text
Next Thread in Python Forum Timeline: "_imaging C module is not installed" thrown in PIL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC