How hard can this be?

D-Man dsh8290 at rit.edu
Mon May 21 11:29:43 EDT 2001


On Mon, May 21, 2001 at 04:12:44PM +0100, Patrick Kirk wrote:
|   if x > 0:
|     print "x is positive"
| 
| You would think anyone could enter that but I can't.  I get the following:
| 
| >>> import math
| >>> if x > 0:
| ...  print "x is positive"
| ...
| Traceback (innermost last):
|   File "<stdin>", line 1, in ?
| NameError: x
| >>>

First, you don't need to import math because you didn't use any
functions from the math module.

When you get a NameError that means you haven't defined what the name
means yet.  Nowhere in your code did you write
    x = <something>
where <something> is an integer or expression of some sort.

Try again, but give x a value first.  Example:

>>> x = 5
>>> if x > 0 :
...     print "x is positive"
...
x is positive
>>>


| >>> import a
| Traceback (innermost last):
|   File "<stdin>", line 1, in
|   File "a.py", line 1
|     if x > 0:
|     ^
| SyntaxError: invalid syntax

This syntax error is probably due to incorrect indentation.  You
haven't shown us the _exact_ text of a.py, so this is just a guess.

-D





More information about the Python-list mailing list