"X not defined"?

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2009
Posts: 3
Reputation: pupspark is an unknown quantity at this point 
Solved Threads: 0
pupspark pupspark is offline Offline
Newbie Poster

"X not defined"?

 
0
  #1
Jun 15th, 2009
  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 46
Reputation: xav.vijay is an unknown quantity at this point 
Solved Threads: 6
xav.vijay's Avatar
xav.vijay xav.vijay is offline Offline
Light Poster

Re: "X not defined"?

 
0
  #2
Jun 15th, 2009
Originally Posted by pupspark View Post
  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]
  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();
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1,614
Reputation: scru has a spectacular aura about scru has a spectacular aura about 
Solved Threads: 131
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Virtuoso

Re: "X not defined"?

 
0
  #3
Jun 15th, 2009
Originally Posted by pupspark View Post
  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.

  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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 3
Reputation: pupspark is an unknown quantity at this point 
Solved Threads: 0
pupspark pupspark is offline Offline
Newbie Poster

Re: "X not defined"?

 
0
  #4
Jun 15th, 2009
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?

  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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 58
Reputation: besktrap is an unknown quantity at this point 
Solved Threads: 1
besktrap's Avatar
besktrap besktrap is offline Offline
Junior Poster in Training

Re: "X not defined"?

 
0
  #5
Jun 15th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 3
Reputation: pupspark is an unknown quantity at this point 
Solved Threads: 0
pupspark pupspark is offline Offline
Newbie Poster

Re: "X not defined"?

 
0
  #6
Jun 15th, 2009
Originally Posted by besktrap View Post
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!
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,067
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 267
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: "X not defined"?

 
0
  #7
Jun 16th, 2009
Originally Posted by pupspark View Post
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...
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 794
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: "X not defined"?

 
-1
  #8
Jun 16th, 2009
>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:
  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
Siddhant Sanyam
(Not posting much)
My Blog: Yatantrika
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 308 | Replies: 7
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC