How hard can this be?
Franz GEIGER
fgeiger at datec.at
Mon May 21 11:34:14 EDT 2001
'NameError' means that the name does not exist.
Assigning first a value to x will do:
x = 1
if x > 0:
print "> 0"
else:
print "<= 0"
Regards
Franz
"Patrick Kirk" <pknews at kirks.net> wrote in message
news:9ebb9d$p43$1 at newsg2.svr.pol.co.uk...
> 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
> >>>
>
> I've tried creating a .py file saying:
> if x > 0:
> print "x is positive"
> and importing it but that doesn't work either.
>
> >>> import a
> Traceback (innermost last):
> File "<stdin>", line 1, in
> File "a.py", line 1
> if x > 0:
> ^
> SyntaxError: invalid syntax
>
>
>
> The worrying thing is that this is copied directly from the tutorial so I
> may well be off to Álan gould's site shortly. But is there something
> obvious that I'm missing?
>
> Thanks in advance.
>
>
More information about the Python-list
mailing list