How hard can this be?

David Cohen dcohen at users.sourceforge.net
Mon May 21 17:30:23 CEST 2001


You don't need to import math.

Try defining x first:

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


Hope this helps.

David


"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